How to Add Rel Canonical in Magento

Following on from our last Magento Blog post where we shared how to increase the page speed of a Magento website, this time I’m going to show you how to add a “rel canonical” to a Magento website.

There are three, yes three ways to add a rel canonical tag to your Magento website’s pages, but before we dive straight in lets quickly go over why adding a rel canonical to a large ecommerce website is important.

Controlling multiple product, category, or dynamic URLs with the same content can be tricky especially on a large ecommerce site. You may have one product that is available in 3 different sizes, colours, shapes where the descriptive content may be being used.

Now, this presents a problem to search engines as they are unsure which page to index from your website and they are very unlikely to show multiple or duplicate product pages within their index.

So, you need to inform search engines which page you wish for them to index by using a rel canonical tag. SEOMOZ have a great illustration of the thought process that the search engines look for.

Magento Rel Canonical 1

Magento Rel Canonical 2

Image credits SEOMOZ

OK, so now you know the importance of adding a rel canonical tag to your pages, let me show you how to add it to your Magneto website.

Option One:

The first way is the fastest way to add a rel canonical tag but certainly not the best way as it doesn’t give you a great deal of control. 

To apply simply click on System > Configuration > Catalog and then click on the option labelled “Search Engine Optimizations”.

search_engine_optimisation_in_magento

Once you've selected this option you will see the following two options:

rel_canonical_in_magento

Then simply change from no to yes and then click on the “Save Config” button in the top right hand corner.

As I mentioned at the start this isn’t the best way to add a rel canonical tag to your Magento site. Why? Because choosing this option is a site wide setting and will give each page its own rel canonical tag pointing to itself and there is no way via this method to define each rel canonical tag.

So if you have the following pages on your website with the same content on each page:

•www.site.com/product-one-100
www.site.com/product-one-200
www.site.com/product-one-500

This setting would then apply an individual rel canonical tag for each page pointing to itself, when the ideal setting would be to point the other two URL’s that end in “500” and “200” to the “100” page.  It doesn't matter which of the two URLs point to another so you could point the “200” and the “100” to the “500” instead.

Option Two:

This is the best method to add a rel canonical to Magento in my opinion, as it gives you much greater control.

Step one is to click on the “Catalog” menu option found along the top of the dashboard;

Magento_Dashboard

Step two click on the “Manage Products” from the drop down menu.

Manage_products

You will then see a list of your products within your Magento store. The next step is to locate two or three products in which you know you have duplicate content, or you've identified can be accessed via multiple or dynamic URLs.

Once you identified these products you will need to click on those products you wish to add the rel canonical to and then click on the product information menu option called “Design”. 

Design_option

Once you’ve clicked the “Design” option you will need to add the following code into the “Custom Layout Update”.

<reference name="head">
<action method="addLinkRel">
<rel>canonical</rel>
<href>http://www.AddYourUrlHere.com/</href>
</action>
</reference>

Adding_rel_cannonical_magento

Once you've placed in this piece of code and have saved it, you will need to place this code into the other product pages you’ve identified by repeating this step for each one. You must make sure that the URL you've placed within the rel canonical tag is the same and points to the page you wish the search engines to index.

So using the same examples previously:

•www.site.com/product-one-100 (Add rel canonical pointing to itself)
•www.site.com/product-one-200 (rel canonical to www.site.com/product-one)
•www.site.com/product-one-500 (rel canonical to www.site.com/product-one)

For safety I always add a rel canonical tag to the main target page just in case it’s accessible via a dynamic url, breadcrumb or anything else for that matter. As far as I’m aware it doesn't do it any harm and I would rather play it safe.

To add the rel canonical tag to your Magento’s websites pages simply select the page you wish to add the rel canonical tag to and then click on the “Design” option on the left hand side.

magento_design_menu_option

Next click on the “Custom Design” box and insert the same piece of code found above into the “Custom Layout Update XML”.

Magento Custom Layout Update XML

Once inserted, hit save and you’re done.

As I mentioned earlier on, this method is by far the best but is the most time consuming. Choosing this option is up to you, but it certainly pays to spend the extra time to make sure each rel canonical tag in your Magento site is pointing to the correct pages, rather than simply applying site wide settings and take the risk of causing a major headache.

There is one final piece of advice I would give when using this option.  Once you have finished adding in your rel canonical tags, run your Magento site through a tool like Screaming Frog to check if you've missed any pages that could require having a rel canonical added. This tool will scan your website for you and you will be able to tell quite easily if any pages do not contain a rel canonical tag within your Magento website.

Screaming Frog

Option 3

The final option is simple but may involve contacting your developer as you will need to manually insert the following tag before the closing </head> tag.

<link rel="canonical" href="/ http://www.AddYourUrlHere.com/" />

To perform this option you will require FTP access and text editors such as NotePad++ or Dreamweaver to edit each page.

Again you will need to identify these pages first before adding in a rel canonical tag to your Magento site.

Bonus Option:

Yoast has created a canonical URL for Magento extension which, once installed, will add rel canonical tags to the <head> section of your Magento website. However, at the time of writing this it is not compatible with Magento 1.7.0.0  and fails to install. Which is a shame, as I use Yoast's plugins and modules for other CMS's so would love the chance to see what this rel canonical Magento extension is like.

I would however always advise where ever possible to not use extra extensions to carry out simple task when they are readily available from within the admin panel of your Magento website. But that is just my opinion and if you know where to look it’s just as easy.

I hope you've enjoyed this post and if you are planning to clean up your Magento website using rel canonical tags I hope this post helps you.  If you've found this post useful don't forget to share it using the buttons below or leave us a comment.

April 19, 2013
Matthew Weeks

Website: www.adurolabs.com

Follow Matt on Google+

2 Comments

  • Tom September 02, 2013 Tom

    Hi Matt,
    This seems like one of the most knowledgeable posts on the topic of canonical links in Magento. I'm far from an expert but have duplicate content issues in webmaster tools, should i use option 1 or 2 from your post,
    as I have a page on root and again the same page in a directory
    ***** a sample message from webmaster tools ********
    Pages with duplicate meta descriptions
    /kit.html
    /tanking/kit.html
    **************************************
    Would greatly appreciate any advise, i have posed on magento community but no replies and forum seems to be fairly quiet with replies,
    thanks
    Tom

    Comment Link
  • Paul Mallam June 27, 2013 Paul Mallam

    Great article here Matt. Not many people know how to add the canonical links to the Magento platform. Glad I found your post.

    Comment Link

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.