You are here:  » Duplicate content - how to integrate Google's new link tag (link rel="canonical")


Duplicate content - how to integrate Google's new link tag (link rel="canonical")

Submitted by jim on Sun, 2009-02-15 09:14 in

Hi there David,
Is it possible to integrate Google's new "canonical" meta tag into Price Tapestry to help avoid any duplicate content penalty?
I was thinking this could be used to eliminate duplicate content when sorting by Price (Low to High, High to Low)
&page=1&sort=priceAsc
&page=1&sort=priceDesc
(and also possibly for pages that use product reviews?)

<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />

I assume this would go into thehtml/header.php file but I'm not entirely sure how to strip the extra sort variables?

Thanks in advance, and I hope this feature might possibly help other users of PT?
Jim

--

More details here:
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html

we now support a format that allows you to publicly specify your preferred version of a URL. If your site has identical or vastly similar content that's accessible through multiple URLs, this format provides you with more control over the URL returned in search results. It also helps to make sure that properties such as link popularity are consolidated to your preferred version.

http://www.example.com/product.php?item=swedish-fish
http://www.example.com/product.php?item=swedish-fish&category=gummy-candy
http://www.example.com/product.php?item=swedish-fish&trackingid=1234&sessionid=5678

<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />

Submitted by support on Mon, 2009-02-16 01:53

Hi Jim,

Yes, this can be done easily in html/header.php, using $_GET["rewrite"] to check that the page has NOT been generated with a search engine friendly URL in the first place. The following code should do the trick (insert before the </head> HTML):

<?php
  
if (($searchresults["numRows"]) && (!$_GET["rewrite"]))
  {
    print 
"<link rel='canonical' href='".$config_baseHREF."search.php?q=".urlencode($q)."' />";
  }
?>

Cheers,
David.

Submitted by magnaromagna on Sun, 2010-06-06 13:12

Great hack, I installed it,
but if I search a product, the result pages show the same rel=canonical and exclude &page number. I mean:

/search.php?q=iphone&page=2&sort=relevance
/search.php?q=iphone&page=3&sort=relevance

show ever rel=canonical /search.php?q=iphone

Is there a way to consider page=2 , page=3 as good, and exclude &sort=relevance ?

Thank you

Submitted by support on Mon, 2010-06-07 09:04

Hi,

Sure - you can include the page parameter (if greater than 1) as follows:

<?php
  
if (isset($searchresults["numRows"]) && ($searchresults["numRows"]) && (!isset($rewrite)))
  {
    
$canonical $config_baseHREF."search.php?q=".urlencode($q);
    if (
$page 1$canonical .= "&page=".$page;
    print 
"<link rel='canonical' href='".$canonical."' />";
  }
?>

Cheers,
David.

Submitted by stevebi on Mon, 2015-04-27 10:51

Hello David,

I am facing the same duplicate Google issue, but as I tried to implement the code, the following error occured

Notice: Undefined variable: searchresults

How can I apply the correct code.

Thanks you for your support

Have a nice day

Steve

Submitted by support on Mon, 2015-04-27 11:33

Hello Steve,

Use the updated replacement above, with the addition of an isset() check to remove the errors.

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Mon, 2015-04-27 11:38

Grateful David,

Cheers

S