What is Rel canonical tag and how can you apply it?

It is normal for a website to have different pages listing same products via different URLs, especially in ecommerce websites.

For example a certain page can display products in price order, brand order, newest products order, rating order etc. When selected a certain order the URL of the page changes from the original URL but you are still seeing the same products.

For example:

The 1st URL is the original URL of the page and the 2nd is generated after selecting the most popular order.

http://www.amazon.com/blue-cufflinks-s/41.htm

http://www.amazon.com/blue-cufflinks-s/41.htm&sort=mostpopular&sessionid=5678asfasdfasfd

Pagination Issue

If Google finds out that these two pages have the same content that is when you are in danger of getting penalized and that is when you use a rel=canonical tag. You will add a rel=canonical tag in the 2nd URL which points to the 1st URL telling Google that the 1st URL is the preferred URL.

How will the rel=canonical tag look like?

<link rel=”canonical” href=”http://www.amazon.com/blue-cufflinks-s/41.htm“/>

Where should rel=canonical tag go?

Head Section

Add a rel=canonical link into the <head> section of the non-canonical version of each HTML page. So in the above example the tag will go into the 2nd URL.

.htaccess

.htaccess is definitely an easy option as most SEOs will have access to the FTP of the website but if you are not use ti .htaccess then I suggest you ask your developer to help you out with this.

Example of the code:

<FilesMatch “blue-cufflinks-s/41.htm&sort=mostpopular&sessionid=5678asfasdfasfd”>

Header set Link ‘< http://www.amazon.com/blue-cufflinks-s/41.htm >;rel=”canonical”‘


<FilesMatch “blue-cufflinks-s/41.htm&sort=mostpopular&sessionid=5678asfasdfasfd”>

The above was to rel=canonical the 2nd URL to the 1st URL. You can also rel=canonical the PDF file to the html file using .htaccess. Most SEOs tend to use robots.txt to avoid pdf files being crawled but by using the rel=canonical you won’t have to do that anymore.

Here is an example of the code:

<FilesMatch “blue-cufflinks.pdf”>
Header set Link ‘< http://www.amazon.com/blue-cufflinks-s/41.htm >;rel=”canonical”‘
<FilesMatch “blue-cufflinks.pdf”>

To test this you can use LIVE HTTP Headers https://addons.mozilla.org/en-US/firefox/addon/live-http-headers/#id=3829

How do you apply the tag in APS.net, APS or PHP?

ASP.Net C#:
<%Response.AddHeader(@”Link”,@”< http://www.amazon.com/>; rel=””canonical”””);%>
ASP VBScript:
<%Response.AddHeader “Link”,”< http://www.amazon.com/>; rel=””canonical”””%>
PHP:
<?php header(“Link: <http://www.amazon.com/>; rel=”canonical””);?>

About saurav

Personal blog of Saurav Rimal, an SEO who likes to write about SEO, sports and unnecessary things.
This entry was posted in Technical SEO and tagged , . Bookmark the permalink.

2 Responses to What is Rel canonical tag and how can you apply it?

  1. SEO Company India says:

    I just want to know why we use this tag. If a page is using this tag then it will be indexed by Google or not ? I need proper clarification.

  2. w3origin says:

    Nice information and very well described. Thank you for sharing such a wonderful information.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>