Do canonical links require a full domain?

HtmlSeoCanonical LinkHtml Head

Html Problem Overview


I want to add canonical links to my pages, but do I need to specify the domain, or will a relative URL do?

In other words, is:

<link rel="canonical" href="/item/1">

good enough, or do I need to use:

<link rel="canonical" href="http://mydomain.com/item/1">

Html Solutions


Solution 1 - Html

Directly from Google:

http://support.google.com/webmasters/bin/answer.py?hl=en&answer=139394

> Can the link be relative or absolute?
> rel="canonical" can be used with relative or absolute links, but we recommend using absolute links to minimize potential confusion or difficulties. If your document specifies a base link, any relative links will be relative to that base link.

Solution 2 - Html

Again, Google says this:

https://support.google.com/webmasters/answer/139066?hl=en

> Avoid errors: use absolute paths rather than relative paths with the rel="canonical" link element. > > Use this structure: https://www.example.com/dresses/green/greendresss.html > > Not this structure: /dresses/green/greendress.html).

For example’s sake, these are their URLs:

http://example.com/wordpress/seo-plugin/

http://example.com/wordpress/seo/seo-plugin/

This is what rel=canonical was invented for. Especially in a lot of e-commerce systems, this (unfortunately) happens fairly often, where a product has several different URLs depending on how you got there. You would apply rel=canonical in the following method:

You pick one of your two pages as the canonical version. It should be the version you think is the most important one. If you don’t care, pick the one with the most links or visitors. If all of that’s equal: flip a coin. You need to choose.
Add a rel=canonical link from the non-canonical page to the canonical one. So if we picked the shortest URL as our canonical URL, the other URL would link to the shortest URL like so in the <head> section of the page:

<link rel="canonical" href="http://example.com/wordpress/seo-plugin/">

That’s it. Nothing more, nothing less.

Solution 3 - Html

All href attributes are hypertext references - that's what it stands for. As such, they are always URI-References, not URIs, and can be relative.

In this case though, there's a benefit in putting in the full URI if you can, because it will survive anything that migrates it onto another domain in the future (assuming you will still want the domain listed to be the canonical one), and can even survive some of the cruder automated plagiarisms :)

That benefit is pretty slight if you aren't actively using non-canonical versions on other domains though, so I wouldn't expend much effort on it.

Solution 4 - Html

There is nothing special about canonical. It’s a standard link type, for use with standard ways to provide links (e.g., the link element), so you can specify any kind of URL reference (absolute, relative, protocol-relative, in combination with the base element, empty, …).

RFC 6596 (The Canonical Link Relation) explicitly says:

> The target (canonical) IRI MAY: > > * Specify a relative IRI (see [RFC3986], Section 4.2).

One of the examples:

> […] or as a relative IRI: > >

Solution 5 - Html

Update on canonical best practices: rel="canonical" has cross-domain support. Google's source: https://webmasters.googleblog.com/2009/12/handling-legitimate-cross-domain.html

Moreover, the introduction of structured data makes the use of canonicals even more strict, as Google will not pick-up the JSON markup from not canonical sources (a mistake I happen to have made!).

Solution 6 - Html

Relative canonical paths are accepted. This one works best:

<link rel="canonical" href="#"/>

It points to the current document's URL – including queries – sans the hash part.

Solution 7 - Html

If you only have one domain for that website, is ok to use the absolute path: <link rel="canonical" href="/item/1">

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRichardView Question on Stackoverflow
Solution 1 - HtmlRemyView Answer on Stackoverflow
Solution 2 - HtmlJosip IvicView Answer on Stackoverflow
Solution 3 - HtmlJon HannaView Answer on Stackoverflow
Solution 4 - HtmlunorView Answer on Stackoverflow
Solution 5 - HtmlAnnaGView Answer on Stackoverflow
Solution 6 - HtmlKHAYRI R.R. WOULFEView Answer on Stackoverflow
Solution 7 - HtmlfemansoView Answer on Stackoverflow