I just wrote a tiny code to deal with canonical link tags. In this code the logic
- reads the URL
- knows the canonical link
- if URL = the canonical link, the code does nothing
- if the URL different than canonical link, the code ads the canonical link meta tag to the source
I think that should be the way Google intended this to work. I was concerned as to having canonical link on the items that have URL that is equal to canonical link, making sure Google does not get confused.
I am not a coder so this code was written only for product_info.php without other SEO modifications such as URL rewrites.
<?php /*** Begin Canonical TAG Mod***/ ?>
// first get products id from URL
$seeID = $_GET['products_id'];
// next get URL from URL
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
// build canonical link you can modify, improve to suit your needs and mods
$canon = tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $seeID, 'NONSSL');
// compare actual URL to canonical link and if they differ
if ( $url !== $canon )
// insert the canonical link tag into header tags
echo '<link rel="canonical" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $seeID, 'NONSSL') . '" />';
// if they do NOT differ, that means Google is on the canonical link version of the page, no canonical link tag is inserted
<?php /*** End Canonical TAG Mod Mod***/ ?>
I figured I will contribute the code here just in case you wanted incorporate it into your code.