6

What is the best way to get canonical links on ALL URL's in D7?

I see nodes already have relative canonicals but I have a site with a lot of non node URL's that also need canonicals.

I added code to my html.tpl.php to add a canonical on any page but now I get double ups on node based pages.

Thanks for anyone taking a look at this.

UPDATE:
I used a theme_html_head_alter() hook to remove the node canonicals.
Then I added new canonicals into the html.tpl.php so every page has them and there is only one on the node pages.

4 Answers 4

7

As mentioned elsewhere, global redirect is a good option. But even Metatag is a good module. It not only handles the canonical urls but also meta keywords, description, Copyright data and many more important Meta data including OG. So, you can also have a check on this module. http://drupal.org/project/metatag and a tutorial on how to get the canonical url to work on this link: http://amitavroy.com/justread/content/articles/canonical-links-and-drupal-7

The one thing with meta tag module is that by default it will print relative canonical urls whereas I have seen major sites like smashingmagazine, engadget etc uses absolute. So, if you want that to happen then the second url is the key.

2
  • This is not really the problem, I want to add canonical link tags to ALL pages, not redirect a bunch of pages. AFAIK it's fine to use relative canonicals.
    – dibs
    May 2, 2012 at 4:32
  • Yes, Meta tags module will add the canonical links to the page headers.
    – Amitav Roy
    May 2, 2012 at 13:39
3

I used a theme_html_head_alter() hook to remove the node canonicals. Then I added new canonicals into the html.tpl.php so every page has them and there is only one on the node pages.

0

Try the Global Redirect module. Here is a quote about it (from the module's project page):

... a simple module which:

  1. Checks the current URL for an alias and does a 301 redirect to it if it is not being used.
  2. Checks the current URL for a trailing slash, removes it if present and repeats check 1 with the new request.
  3. Checks if the current URL is the same as the site_frontpage and redirects to the frontpage if there is a match.
  4. Checks if the Clean URLs feature is enabled and then checks the current URL is being accessed using the clean method rather than the 'unclean' method.
  5. Checks access to the URL. If the user does not have access to the path, then no redirects are done. This helps avoid exposing private aliased node's.
  6. Make sure the case of the URL being accessed is the same as the one set by the author/administrator. For example, if you set the alias "articles/cake-making" to node/123, then the user can access the alias with any combination of case.
  7. Most of the above options are configurable in the settings page. In Drupal 5 you can access this after enabling the globalredirect_admin module. In Drupal 6, the settings page is bundled into the module.
0
0

Download the Metatag module, go to its settings and

  1. Click "edit" next to the Global settings
  2. Go the Canonical URL field (under the Advanced tab)
  3. Fill out the following: http://yourdomain.com[current-page:url:relative]

This will come in handy when you use multiple domains for one website. It will avoid duplicate content flags.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.