Amitav Roy

Blog on web and travel

Canonical links and Drupal 7

Posted on 5 Apr 2012 by Amitav Roy

Canonical links and Drupal 7

Recently when I was reading about canonical links and its support with Drupal 7, and I was really happy to see that as always Drupal handles these issues perfectly (rather almost perfectly) out of the box.

Canonical link and Drupal

When I first read about canonical links, the first thing that came to my mind was: what if all the links that have an alias are indexed using the default path of Drupal? For example, my article “My first post” which might have a URL http://www.domain.com/my-first-post can also be accessed by http://www.domain.com/node/1 or even http://www.domain.com/?q=node/1

Yeah, this can be a nightmare from SEO perspective, if this is not handled properly. Well, the best part is that Drupal already does this for us and we don’t need to worry about this.

After reading this article: http://googlewebmastercentral.blogspot.in/2009/02/specify-your-canonical.html I was quite clear about what is Canonical links, what are they for and their best practice. The only thing that I found was not happening with Drupal 7 out of the box was that the canonical links were relative and not absolute. For Google, both work fine and there is nothing wrong or proffered option for this. But when I checked what some of the renowned sites were following, it was clear that the links were absolute. Clearly, they wanted to play safe and so, we should also do the same. This is where the Meta Tags module from Drupal comes to the rescue. Inside Meta tags module’s configuration page we can set the canonical URL pattern to be absolute. Check the screenshot:

You need to override the Global settings and then go inside the advanced settings options to see these set of options:

This makes sure that the canonical URLs for the site are absolute. Here is a screenshot of the absolute canonical URLs for my site:

Duplicate links because of system URLs (node/[nid])

Then the next thing to handle is the duplicate link issue. URLs such as node/1 should not work. So, this is where we will be using the global redirect module. Once you have the module installed and running, you just need to go to the configuration page and check if the settings are something like this: