Ok, I did it (well, sort of). Here is a beta (or better: proof of concept) for the new tag which tells the search engines Google, Yahoo! and Live which URL it should have for the current page. Matt Cutts (software engineer at Google) explains the new canonical tag:
The syntax is pretty simple: An ugly url such as http://www.example.com/page.html?sid=asdf314159265 can specify in the HEAD part of the document the following:
<link rel="canonical" href="http://example.com/page.html" />
That tells search engines that the preferred location of this url (the “canonical” location, in search engine speak) is http://example.com/page.html instead of http://www.example.com/page.html?sid=asdf314159265.
What can it do for my webshop?
If search engines find the same content on irregular/different URL, the page/content will be marked as “duplicate content”. This is a common mistake which you want to avoid since you want to have all your pages indexed properly. However, there are some factors that can lead to several URL’s for one page.
In osCommerce there URL’s displays the category ID, the product ID and a session ID. Every new visit(or) has a unique session. Here lies the problem: the unique session ID creates an irregular URL for the same page! This can create duplicate content.
You want to tell the search engines that the product page is found here
and not here
(where osCsid is unique for every new visit(or))
How to implement the canonical tag in your webshop
I must warn you, this is just a quick and dirty test. The contribution with optimized code and (probably) more compatibility will follow very soon.
You only have to adjust two files: index.php and product_info.php.
- Open both files and add before require(‘includes/application_top.php’); the following code:
$string = $_SERVER['REQUEST_URI']; $search = '&osCsid.*|?osCsid.*'; $replace = '';
- Add within your <head> section the following code to generate the correct URL:
<link rel="canonical" href="<?php echo 'http://www.yourdomain.com' . ereg_replace( $search, $replace, $string ); ?>" />
- Don’t forget to replace yourdomain.com with your actual domain name.
As I said, this is just a quick and dirty test. Compatible with and without search engine friendly URL’s. Although I tested it on three different osCommerce setups, it might not work for your installation. Please wait till the stable contribution.