Connect with us

Mark Rushworth

PHP Canonical URL Script

web-design

PHP Canonical URL Script

On a recent project we had multiple duplicates of product detail pages mainly due to querystrings setting the sizes of the products. To combat this I decided to use the new Canonical REL URL tag now supported by Google, Yahoo and MSN and thought that if you’re experiencing the same issue that you’d appreciate this elegant solution to your own canonical url problems.

In the head just enter:

<link rel=”canonical” href=”http://www.website.com<?php echo $_SERVER[‘PHP_SELF’]?>”>

if you’re using a rewritten path then it needs to be changed to:

<link rel=”canonical” href=”http://www.website.com<?php echo parse_url($_SERVER[‘REQUEST_URI’],PHP_URL_PATH);?>“>

What this does is write in the url without the querystring in essence telling Google and the others that the non querystringed page is the one they should really index (googles supposed to 301 the links across).

Continue Reading
You may also like...
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More in web-design

To Top