How to Optimize Use Of Canonical URLs In Magento

by Akshay Sangodkar | October 02, 2016 | 0 Comments

Introduction

This step-by-step tutorial is designed to help developers and users optimize use of canonical link meta tags in Magento Ecommerce Platform content pages, category pages, and product pages. Search engines such as Google, Bing, Yandex, and Yahoo! impose duplicate content penalties on websites, which may affect their ranking in search results. Canonical URLs help search engines crawl duplicate content only once by indicating the URL that contains most of the duplicate content.
The tutorial involves editing PHP files, therefore some knowledge of PHP and HTML is needed to execute the steps. Also, please remember to make a backup of files that are to be edited.
We also use the “15-Minute SEO Audit” with RankSense free Chrome Browser Extension to detect common SEO issues and help optimize.

Duration To Complete: 20 mins

Prerequisites

Magento Open Source Ecommerce Platform v1.9.1.0

Step 1

In Magento Admin Panel, go to System –> Configuration –> Catalog –> Search Engine Optimizations. Set Use Categories Path for Product URLs and Use Canonical Link Meta Tag For Products to Yes. Here is a snapshot.
With Use Canonical Link Meta Tag For Products set to Yes, Magento automatically generates canonical link meta tags for products pages. With Use Categories Path for Product URLs set to Yes, each product web page can be accessed using two URLs, one with the categories path, for example http://magento.samplestore.biz/mobiles/boogle-texus-6.html and one without, for example http://magento.samplestore.biz/boogle-texus-6.html. Though these are duplicate URLs, the canonical link meta tag eliminates the duplicity.
Press Ctrl + Shft + i in Google Chrome browser to access developer tools. Click on the RankSense tab to use the extension to check canonicalization of a product page as shown in the snapshot below.

Step 2

The canonical link meta tag for categories in Magento is automatically generated depending on an SEO setting in Admin Panel. In Magento Admin Panel, go to the System –> Configuration –> Catalog –> Search Engine Optimizations section. Below is a snapshot that shows Use Canonical Link Meta Tag For Categories set to Yes.

Press Ctrl + Shft + i in Google Chrome browser to access developer tools. Click on the RankSense tab to use the extension as shown in the snapshot below. Analyzing pagination tags for page 2 of a category in our sample Magento store, we find that there is one pagination warning which says Canonical tag is not self-referential. This is a common mistake and means that the canonical tag cannot be the first page in the set.

Set Use Canonical Link Meta Tag For Categories to No. This will disable auto-generation of canonical link meta tags for categories. Below is a snapshot.

In the Magento base directory (in our setup it is /var/www), we modify the code in the template file app/design/frontend/base/default/template/page/html/head.phtml which generates the head part of an HTML page in Magento. It’s best not to modify files in the base theme, so we copy head.phtml to the rwd theme while preserving the folder structure.
The new template file is stored as app/design/frontend/rwd/default/template/page/html/head.phtml. If you already have head.phtml in your theme, then use that template file instead.
Open app/design/frontend/rwd/default/template/page/html/head.phtml in your favorite editor. Add the following code snippet at the end of the file.
[php] $actionName = $this->getAction()->getFullActionName();
if ($actionName == ‘catalog_category_view’) // Category Page
{
$category = Mage::registry(‘current_category’);
$prodCol = $category->getProductCollection()->addAttributeToFilter(‘status’, 1)
->addAttributeToFilter(‘visibility’, array(‘in’ => array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)));
$tool = $this->getLayout()->createBlock(‘page/html_pager’)->setLimit($this->getLayout()-
>createBlock
$linkNext = false;
if ($tool->getCollection()->getSelectCountSql()) {
if ($tool->getLastPageNum() > 1) {
if (!$tool->isFirstPage()) {
$linkPrev = true;
if ($tool->getCurrentPage() == 2) {
$url = explode(‘?’, $tool->getPreviousPageUrl());
$prevUrl = @$url[0];
}
else {
$prevUrl = $tool->getPreviousPageUrl();
}
}
if (!$tool->isLastPage()) {
$linkNext = true;
$nextUrl = $tool->getNextPageUrl();
}
}
}
if ($linkPrev) echo ”; if ($linkNext) echo ”; echo ‘getCurrentUrl() . ‘” />’;
}
[/php] This generates self-referential canonical link meta tags for category pages in Magento, and also generates pagination tags.
After implementing Step 2 in the sample Magento store, the resulting HTML of Page 2 of a category is as follows.
<link rel=“prev” href=“http://magento.samplestore.biz/accessories-9.html” />
<link rel=“next” href=“http://magento.samplestore.biz/accessories-9.html?p=3/>
<link rel=“canonical” href=http://magento.samplestore.biz/accessories-9.html?p=2″ />
Analyze using RankSense Browser Extension again as follows. It shows that the issue is fixed.

Check using Google Chrome developer tools. Below is a snapshot.

Conclusion

With these simple steps we have reduced duplication of content using canonical link meta tags for categories and products in Magento. Using RankSense Browser Extension we have ensured that canonicalization is optimized by generating self-referential canonical link meta tags for category pages in Magento.

Akshay Sangodkar

0

REPLIES

Comments are closed.

Try our SEO automation tool for free!

RankSense automatically creates search snippets using advanced natural language generation. Get your free trial today.

OUR BLOG

Latest news and tactics

What do you do when you’re losing organic traffic and you don’t know why?

Getting Started with NLP and Python for SEO [Webinar]

Custom Python scripts are much more customizable than Excel spreadsheets.  This is good news for SEOs — this can lead to optimization opportunities and low-hanging fruit.  One way you can use Python to uncover these opportunities is by pairing it with natural language processing. This way, you can match how your audience searches with your...

READ POST
Making it easier to implement SEO changes on your website

Changes to the RankSense SEO rules interface

As we continue to improve the RankSense app for Cloudflare, we are always working to make the app more intuitive and easy to use. I'm pleased to share that we have made significant changes to our SEO rules interface in the settings tab of our app. It is now easier to publish multiple rules sheets and to see which changes have not yet been published to production.

READ POST

How to Find Content Gaps at Scale: Atrapalo vs Skyscanner

For the following Ranksense Webinar, we were joined by Antoine Eripret, who works at Liligo as an SEO lead. Liligo.com is a travel search engine which instantly searches all available flight, bus and train prices on an exhaustive number of travel sites such as online travel agencies, major and low-cost airlines and tour-operators. In this...

READ POST

Exciting News!
seoClarity acquires RankSense

X