Canonical URLs


Duplicated content across multiple pages hurts your search engine relevancy. But what do you do when the same page can be accessed with multiple urls? Perhaps your page allows the use of query string variables? Or your page path works both with and without a trailing slash? Or in the case of concrete5, it also works with the page's unique id. Fortunately Google and Yahoo have come up with a great solution to this problem: the Canonical Link tag

Implementing a canonical urls on your concrete5 website is pretty straight forward. Just add the following snippet to your theme's header include:

<? $cPath = $c->getCollectionPath();
$canonicalURL = BASE_URL;
$canonicalURL.= $cPath;
$pageIndentifierVars = array('keywords','fID','tag','productID');
$canonicalVars = array();
foreach($pageIndentifierVars as $var)
if($_REQUEST[$var]) $canonicalVars[]= $var.'='.$_REQUEST[$var];
if( count($canonicalVars) ) $canonicalURL.= '?' . join(',',$canonicalVars);
<link rel="canonical" href="<?= $canonicalURL ?>" />

Note that in the above example I'm also adding a few key query-string variables to the canonical url if they're present. This is because I want the search engines to treat each url with unique versions of these parameters to be treated as separate pages.

Like this post?
Tweet This

Enjoy this post?