Canonical Link Tag
Note: This article was written in 2011 and may be out of date. If you find better resources, please leave a comment and I’ll update the article.
I find there is still some confusion with canonical link tag. Here I explain and provide resources to everything canonical tag realted in this article.
What does Canonical link tag do?
A canonical link tag is used to replace a 301 redirect, when you don’t have access the tools necessary to redirect a page.
It’s main intent is to reduce duplicate content crawled by search engines.
In this video, Matt Cutts recommends using 301 redirects instead of canonical links.
He gives good examples and explains when to use each option. Update: In later videos he says to use both.
How To Use A Canonical Link Tag
The tag goes in the tags on your page. It looks like this:
<link rel="canonical" href="https://nickyeoman.com/new_page"/>
PHP Canonical Link Tag
Here is a PHP snippet for your website for your tag:
<?php
$canonicalLink = "https://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
?>
<link rel="canonical" href="<?php echo($canonicalLink); ?>">```
Canonical Link Tag Gotchas
Canonical tags only work within your domain, for example when your redirecting www to non-www.
301 Redirect
If you have the option to do 301 redirects but don’t know how, checkout my article Using Apache for 301 redirects.
Canonical Loop
Google handles a canoincal loop, so you can point a page to itself.
You still might not want to do this as it is unclear how search engines other than Google handle a canonical loop.