April 12th, 2015
Too often ignored or misused, canonical URLs represent a key factor to improve your websites’s SEO and they are actually a very simple technique to understand and deploy.
Basically, canonical URLs tell Google (and other search engines) which is the preferred URL they should index when the same content is served through multiple URLs. This is a very common issue on dynamic websites or online stores. Look at the following examples:
Your server is configured to offer the same content with or without the “www.” subdomain (this is super-common). Generally, it is suggested to use the complete version (with “www.”) as the canonical URL.
Your server is configured to offer the same content on HTTPS protocol (for example when the user is logged in). Google suggest to set the HTTPS version as the canonical URL.
Your server is configured to offer your default home page with or without its file name. You should use the domain-only version (without file name) as the canonical URL.
Your server is configured to offer the same content with or without the trailing slash. It’ usually suggested to use the version with trailing slash as the canonical URL.
Dued to dynamic URLs, the same page is reached through different URLs as a result of category browsing.
Dued to dynamic URLs, the same product category can be reached through different URLs (e.g., depending on different querystring parameters).
All the above examples would greatly enjoy a correct use of canonical URLs in order to:
- Consolidate duplicate or similar content on search engines
- Consolidate tracking metrics for a single product, article or category served through different URLs
- Defining the URL you want people to see
How To Setup The Canonical URL Attribute
Now, take the example #1 above and suppose you want to set
http://www.example.com/content.html to be the prefered URL. The easiest and most effective method to do this is including the following line into the
<head> section of that page:
<link rel="canonical" href="http://www.example.com/content.html" />
It’s just that simple. Rememeber to always use absolute paths and not relative paths when declaring canonical URLs. The following line, for example, is wrong:
<link rel="canonical" href="/content.html" />