In Drupal, the canonical URL for nodes is the node/<nid> URL.
It is not correct to use the path alias as canonical URL; it should be viceversa, with node/<nid> being set as canonical URL for each of the path aliases associated to the node.

That is true for any path aliases.

Comments

avpaderno’s picture

Title: Canonical URL generated for nodes is not correct » Generated canonical URL is not correct
Status: Active » Fixed

The code has been changed, and committed in CVS (#301482, #301484 for branch 6.x-1; #301488, #301490 for branch 6.x-3).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jcisio’s picture

Version: 6.x-1.8 » 6.x-1.x-dev
Status: Closed (fixed) » Active

By using alias, the path node/%nid doesn't really exist (because we never use it). Search engine should not bother about this path. If someone visits node/%nid by mistake (by typing this url), we need to tell Google the canonical url is the other, but not vice versa.

EvanDonovan’s picture

I agree with jcisco. This is doubly true if you are using Global Redirect module, as many people who use Nodewords no doubt are.

Anonymous’s picture

Status: Active » Closed (fixed)

See the latest development of the code; if you prefer to use the path alias to generate the canonical URL, you can use the right token implemented by nodewords_tokens.module.

jelo’s picture

I do not want to change the status, just have some follow up questions. I am using Global and Path Redirect as well as nodewords and pathauto. The problem in my opinion with canonical URLs is not the clean vs. non-clean URL path, but cases where you have multiple aliases for a single node.

Example:
www.domain.com/node/5
www.domain.com/my-first-alias
www.domain.com/my-second-alias-for-node-id-5

How do I classify which page is my true source with regard to SEO? Just imagine you have used an alias for 1 year, but then the need comes up to change it to something else. You would want to keep the old alias, but attach a canonical link to the new alias (and not necessarily the node/nid path).

Wouldn't pathauto be the right place to organize this? With each alias it could store if it is the primary alias or one of many secondary aliases (there can only be one primary). Right now pathauto offers the following configuration options:
Update action:
Do nothing. Leave the old alias intact.
Create a new alias. Leave the existing alias functioning.
Create a new alias. Delete the old alias.

When pathauto knows which alias is the primary alias, it could add the option to create a new alias and include a canonical link into the existing and/or all other secondary aliases that are not primary.

Regards, J.

Z2222’s picture

In Drupal, the canonical URL for nodes is the node/ URL.
It is not correct to use the path alias as canonical URL; it should be viceversa, with node/ being set as canonical URL for each of the path aliases associated to the node.

This is not true. When you have a URL like http://example.com/my-page, the canonical URL is http://example.com/my-page not http://example.com/node/123. If you put node/123 as the canonical URL it is very bad for SEO. Google will stop showing http://example.com/my-page in the search engine results pages and will instead show the nonexistant node/123 URLs.

The checkbox to show the aliased paths should be checked by default. Changing that will mess up the SEO on countless websites. I'm searching through the issue queue, because I just noticed that the checkbox was unchecked on a couple of my websites, which is a recent change that I didn't make. If this setting change was done by the module during an update, it is probably causing SEO problems for many websites. I'm still not sure how the setting got changed on my sites...

Z2222’s picture

The problem in my opinion with canonical URLs is not the clean vs. non-clean URL path, but cases where you have multiple aliases for a single node.

For best results, you shouldn't have multiple aliases for a single node. There should be 301 redirects from all the duplicate aliases to the single correct alias. Even the node/123 URLs should do 301 redirects to a single correct URL alias. The only URLs that should be visible to users and search engines should be the URL aliases.

jelo’s picture

Google will stop showing http://example.com/my-page in the search engine results pages and will instead show the nonexistant node/123 URLs.

This is not entirely correct. Google does not guarantee that it will use the canonical URL in the index. They only state that they take your canonical link tag into consideration to determine which page to index (Source e.g. http://www.mattcutts.com/blog/canonical-link-tag-video/). In many cases it will be the page that you identified as canonical, but it does not have to be this way. If for example your internal links all use the node/123 URL as link and important external sites link to yoursite.com/node/123, Google might use that as the canonical URL.

For best results, you shouldn't have multiple aliases for a single node. There should be 301 redirects from all the duplicate aliases to the single correct alias.

I agree. That is actually the recommendation of Google as well. My use case is not really applicable any more.

Z2222’s picture

This is not entirely correct....If for example your internal links all use the node/123 URL as link and important external sites link to yoursite.com/node/123, Google might use that as the canonical URL.

It may not be true in every case, but it has already happened to me on three sites, entirely due to this module's configuration. :)

The first time was a while ago. I think I posted an issue about it, and then the default was changed. The second and third times were discovered today.

100% of the internal and external links on all three sites point to the aliased paths, not the node/123 URLs which have never been exposed to the public. One was originally a vbulletin site and the other was a punBB site...

jelo’s picture

I am not claiming that this might not have happened. Personally, I would consider it likely that it happens as you describe in the majority of cases. All I am pointing out is that this is not a 100% business rule as Google itself states that they only take it as one indication. I do not know what it takes for Google to go against your indication, but the possibility in theory exists... It probably just covers the standard approach if they see potential abuse of the tag for whatever purpose, they are in a position to do whatever they want.