Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

rel="canonical" and product pages


longhorn1999

Recommended Posts

Hi,

 

I was wondering if anyone could comment on the rel="canonical" tag for product pages. I'm using Ultimate SEO Urls 5 with RC2a.

 

It's easy enough to add the tag to the home page, but putting it on product page is a bit more complicated it seems.

 

Google's instructions aren't particular clear to me: http://www.google.com/support/webmasters/bin/answer.py?answer=139394

 

One example of it's usage is in post 159 in this thread: http://www.oscommerce.com/forums/topic/330479-what-is-the-oscsid-why-you-must-not-loose-it/page__st__140

 

<link rel="canonical" href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=235' . (int)$_GET['products_id'],NONSSL,false); ?>" />,

 

Spooks also gave an example back in 2009 in post 8 here: http://www.oscommerce.com/forums/topic/329838-canonical-tag-implementation/

 

<link rel="canonical" href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$_GET['products_id'],'NONSSL',false); ?>" />

 

I'm not even sure that I need this tag, but Google seems to require it if you want to have any hope of getting rich snippets in your search results:

http://www.google.com/support/merchants/bin/request.py?contact_type=rich_snippets

 

Any idea how to best implement this in product_info.php?

 

 

Thanks

Link to comment
Share on other sites

There are an add-on or two for adding in canonical tags, also some of the newer meta tags add-ons have it "built in"

Link to comment
Share on other sites

http://addons.oscommerce.com/category?search=canonical

 

The only one I see that somewhat addresses what I'm looking for is the add-on from July 5, 2010. Unfortunately it looks much more complex than it needs to be and uses some questionable code (eregs for example):

 

Manual installation (for modified osCommerce shops):

 

Open the file /catalog/includes/functions/general.php

Add the following lines to general.php just before the php closing tag ( ?> ) at the bottom

 

 

// starts canonical tag function - www.webshoptimizer.com

function CanonicalUrl() {

$domain = substr((($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER), 0); // gets the base URL minus the trailing slash

$string = $_SERVER['REQUEST_URI']; // gets the url

$search = '\&osCsid.*|\?osCsid.*'; // searches for the session id in the url

$replace = ''; // replaces with nothing i.e. deletes

 

$str = $string;

$chars = preg_split('/&/', $str, -1);

 

if($chars[1]){

$newstring= "?".$chars[1];

}

if($chars[2]){

$newstring = $newstring ."&".$chars[2];

}

 

if($newstring){

echo $domain . ereg_replace( $search, $replace, $string) . $newstring;

}else{

echo $domain . ereg_replace( $search, $replace, $string);

}

}

// eof - canonical tag

 

Open from your catalog directory index.php and product_info.php

Add within your <head> section the following code to generate the correct URL:

 

<link rel="canonical" href="<?php CanonicalUrl(); ?>" />

 

Save your files and check your store. Done!

 

To test if the contribution is installed correctly, open a productpage and compare the URL in your address bar (of your browser) with the one in the source. If you look in the source the canonical link tag should show the same URL as in the address bar minus the session ID.

 

You can also add the function (step 4) to other files if the content is of any value to your site. Files where the function (step 4) can be added:

 

product_reviews.php

shipping.php

privacy.php

conditions.php

contact_us.php

 

Add the function to other contributions whom add pages to your website too (e.g. newsdesk, faq, etc).

 

I'm using Jack_mcs's version of Header Tags and FWR_media's Ultimate SEO Urls, and don't want to modify these if I don't have to, yet I need them to still function w/ the rel="canonical" tag.

 

I'm still hoping that one line in the <HEAD> of product_info.php would do the trick, though maybe that's wishful thinking.

Link to comment
Share on other sites

Steve,

 

Do you mean Header Tags v3.2.5? I'm already using that and I don't believe the canonical tag is in there, at least for product pages.

 

http://addons.oscommerce.com/info/5851

 

Jack uploaded the latest version on 6/20/11, and 3 1/2 days later it's still in add-on purgatory right now, waiting for someone to approve it.

Link to comment
Share on other sites

longhorn1999, I was looking for help with the canonical tag when I came across you post.

 

I don't know if it will help, however, did you see "Sam's Remove & Prevent duplicate content with the canonical tag" contribution (located at http://addons.oscommerce.com/info/7163)? The support thread is located at http://www.oscommerce.com/forums/topic/350604-remove-prevent-duplicate-content-with-the-canonical-tag/. There seems to be updated coding available in the support thread that is not included in the most-recent version of the contribution.

Link to comment
Share on other sites

 

I don't know if it will help, however, did you see "Sam's Remove & Prevent duplicate content with the canonical tag" contribution (located at http://addons.oscommerce.com/info/7163)? The support thread is located at http://www.oscommerce.com/forums/topic/350604-remove-prevent-duplicate-content-with-the-canonical-tag/. There seems to be updated coding available in the support thread that is not included in the most-recent version of the contribution.

 

Oops. Judging by spooks's post (#50) the in the support thread, it appears that "Sam's Remove & Prevent duplicate content with the canonical tag" contribution will not work with search-engine-friendly urls.

 

I, too, have SEO-friendly URLs and trying to find a contribution to correctly produce a canonical tag. I searched the contributions for "canonical." Ultimate SEO URLs (http://addons.oscommerce.com/info/2823) appears in the results but I cannot find mention of canonical in the contribution. (I was hoping I could update my version of Ultimate SEO URLs to a newer version that included the canonical tag.)

 

I also installed (and, since removed) Canonical URL links (http://addons.oscommerce.com/info/6578). I don't know about the "questionable code" longhorn1999 mentioned. (I don't know code very well.) The contribution didn't seem to handle all situations very well. It seemed to properly produce the canonical tag for products and the first page of a category. However, it did not address multiple-page categories, new products, etc. It also returned a canonical tag including "http" for SSL pages.

 

Is there a canonical tag contribution that will work with existing Ultimate SEO URLS and meta tag contributions?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...