The rel=canonical element, often called the “canonical link”, is an HTML element that helps webmasters prevent duplicate content issues. It does this by specifying the “canonical URL”, the “preferred” version of a web page. Using it well improves a site’s SEO.
The idea is simple: if you have several similar versions of the same content, you pick one “canonical” version and point the search engines at that. This solves the duplicate content problem where search engines don’t know which version of the content to show.
The SEO benefit of rel=canonical
Choosing a proper canonical URL for every set of similar URLs improves the SEO of your site. Because the search engine knows which version is canonical, it can count all the links towards all the different versions, as links to that single version. Setting a canonical is similar to doing a 301 redirect, but without actually redirecting.
The process of canonicalization
When you have several choices for a products URL, canonicalization is the process of picking one. In many cases, it’ll be obvious: one URL will be better than others. In some cases, it might not be as obvious, but then it’s still rather easy: pick one! Not canonicalizing your URLs is always worse than canonicalizing your URLs.
How to set canonical URLs - Correct example of using rel=canonical
Let’s assume you have two versions of the same page. Exactly, 100% the same content. They differ in that they’re in separate sections of your site and because of that the background color and the active menu item differ. That’s it. Both versions have been linked from other sites, the content itself is clearly valuable. Which version should a search engine show? Nobody knows.
For example’s sake, these are their URLs:
http://example.com/wordpress/seo-plugin/
http://example.com/wordpress/plugins/seo/
This is what rel=canonical was invented for. Especially in a lot of e-commerce systems, this (unfortunately) happens fairly often. A product has several different URLs depending on how you got there. You would apply rel=canonical as follows:
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/">
What this does is “merge” the two pages into one from a search engine’s perspective. It’s a “soft redirect”, without redirecting the user. Links to both URLs now count for the single canonical version of the URL.
When should you use canonical URLs? 301 redirect or canonical? If you have the choice of doing a 301 redirect or setting a canonical, what should you do?
The answer is simple: if there are no technical reasons not to do a redirect, you should always do a redirect. If you cannot redirect because that would break the user experience or be otherwise problematic: set a canonical URL.