How to Add Canonical URLs in Magento 2?

How to Add Canonical URLs in Magento 2?

Canonical URLs Magento help optimize your ecommerce website for search engines. They ensure that search engines index the right version of your content, preventing any negative impact on your website's search engine rankings due to duplicate content. If you're new to canonical URLs or need guidance on adding canonical urls in Magento 2, this article can assist you.

This write-up explores the importance of canonical URLs in Magento 2 and their potential to improve your website's search engine rankings. We'll also discuss how Googlebot chooses the canonical URL and highlight the most common forms of duplicate content in Magento 2.

We provide a step-by-step guide on how to add canonical tags to your product, category, and CMS pages. Follow these instructions to start incorporating canonical URLs into your Magento 2 website.

What is Canonical Tag?

Canonical tags, also known as rel=canonical tags, are an essential aspect of website optimization for search engines in Magento 2. It is an HTML specification that appears in the source code of a website’s header area.

These HTML elements allow you to signal to search engines which page version should be considered authoritative. It is useful when there are multiple versions of the same content.

When search engines crawl a website, they analyze the content on each page to check its value and relevance to users. However, duplicate content can confuse search engines and negatively impact a website's rankings.

For example, a website may have two identical product pages with different URLs. In that case, search engines may struggle to determine which page to display in search results. It then results in lower search engine rankings.

This is where the canonical meta tag become essential. It means adding a canonical urls to a page to inform search engines which page version should be preferred. It eliminates the effects of duplicate content on search engine rankings. You can ensure the most relevant page version is displayed in search results.

Search engines will only index the source if a canonical meta tag is correctly marked. The rel=canonical tag can be added to the code for all duplicate pages, pointing to the source canonical page.

Why Canonical Tag is important for SEO in Magento 2

If a lot of the same content is detected on your site, Google may penalize your domain and decrease the SERP ranking.

For an e-commerce site like Magento 2, it is a common issue because of the high variation in URLs. With appropriate use of the canonical meta tag, you can instruct the crawlers which link should be the original and get a high-ranking site.

In Magento 2, using canonical meta tag on product and category pages and CMS pages is especially important. This strategy can improve a website's search engine rankings and ensure that the most relevant page appears in search results, increasing website traffic and engagement.

How does Googlebot choose the canonical URL?

Googlebot is a crucial component of Google's search engine crawler that significantly recognizes a page's canonical URL. It scrutinizes the content of each page while crawling a website to gauge its significance and usefulness to users.

When a website features identical content, the canonical tag lets Googlebot identify the primary page version. Googlebot considers multiple factors when determining the canonical URL, including

  • Content similarity Googlebot examines the content on each page to establish the degree of resemblance between them. Googlebot utilizes the canonical tag to indicate the preferred version if the content is similar or identical.

  • User signals Googlebot also evaluates user signals like click-through and bounce rates. It recognizes the page version that is more popular among users, indicating that it is more likely to be the preferred version.

  • Link signals When identifying a page's preferred version, Googlebot considers link signals. It includes the links pointing to each page version to determine which one is more authoritative.

    To ensure that Googlebot selects the correct canonical URL for a page, it is essential to use canonical tags precisely and consistently throughout the website.

Apart from evaluating the content on a website, Google also reviews various other factors, including the security protocols of the page (HTTP), sitemaps, and "rel=canonical" labels, to identify the appropriate canonical URL.

Common types of duplicate content in Magento 2-

Understanding the different types of duplicate content in Magento 2

Duplicate content can decrease the relevance of a website's content and reduce its authority, leading to lower search engine rankings. As a result, it is crucial to identify and address any instances of duplicate content in Magento 2 to avoid these problems.

Partial duplicates - A minor part of the content or its layout is unique. Common examples of partial duplicates in Magento stores include-

  • Product sorting.
  • Pagination.
  • Variations of the same product.
  • Category pages with similar content
  • CMS pages with partially similar content
  • URLs with session IDs that create multiple versions of the same page.

Full duplicates occur when the content on two or more pages is identical.

Complete duplicate examples in Magento include

  • Same product in different categories
  • Category pages with identical content
  • CMS pages with identical content

How To Add Canonical URL In Magento 2

Optimizing website content for search engines is a critical step in Magento 2, and start adding canonical URL to product and category pages as well as CMS pages is an essential part of it. Here is a step-by-step guide on adding canonical tags to each page type.

1. Adding Canonical Tags to Product and Category Pages

  • Log in to the Magento 2 admin panel to enable canonical urls for your store. Navigate to Stores > Settings > Configuration

A screenshot of adding Canonical URLs in Magento 2

  • Choose Catalog > Catalog

A screenshot of adding Canonical URLs in Magento 2

  • Go to the "Search Engine Optimization" section. Use Canonical Link Meta Tag For Categories” and “Use Canonical Link Meta Tag For Products”.

A screenshot of adding Canonical URLs in Magento 2

  • Canonical tags will be applied to your product and category pages after you select these options.
  • Save the changes.

Other Canonical Tag changes include:

If you want a search engine like Google to index the pages with complete category URL path only, make the changes:

  • Set Use Canonical Link Meta Tag for Categories – ‘Yes’
  • Use Canonical Link Meta Tag for Products – ‘No’

If you want Google to index the products pages only, add canonical meta tag for categories to “No”. Enable canonical meta tag for products. Change the following settings:

  • Use Canonical Link Meta Tag for Categories – ‘No’
  • Use Canonical Link Meta Tag for Products – ‘Yes’

If you want Google (or other search engines) to index categories and product URLs, enable both the options:

  • Use Canonical Link Meta Tag for Categories – ‘Yes’
  • Use Canonical Link Meta Tag for Products – ‘Yes’

Save the changes and clear the cache after the changes are made.

2. Add Canonical URL to CMS Pages

To add canonical tag to your CMS pages; we first identify the specific pages. In this instance, we will add a canonical tag to the default About Us page.

Create an .XML file containing our updated layout. You have to add it to the folder in the Magento directory.

The filename of our XML files should contain the following format:

cms_page_view_selectable_<CMS Page Identifier>_<Name for Layout Update>.xml

For the About Us page, we’ll have the XML file format shown below:


In the formate shown above:

  • about-us: is the CMS Page Identifier. You have to add custom canonical tag based on the Magento website page.
  • test: the name for our layout update. The name is later displayed as an option in your Magento Admin Panel.

After creating the XML file, add the following code:

<?xml version="1.0"?>
<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
     <link rel="canonical" src="" src_type="url"/>
  • Replace with your chosen canonical URL. The code will add a canonical URL into your CMS page’s .

  • Place the file in: your_Magento_root)\vendor\magento\theme-frontend-luma\Magento_Theme\layout

  • Flush cache using the following command:

php bin/magento cache:flush

  • You can see a test option that is selectable from the Magento Admin Panel. Go to Content > Pages > About Us > Design > Custom Layout Update and choose “test”.

Canonical tag implementation for Magento 2 CMS pages

  • Save the configuration and refresh your front end.

When inspecting your About Us page, you should see a canonical URL in the page’s .

You can use tools like Google Search Console to check if Googlebot recognizes the canonical URL.

3. Additional methods on how to specify a canonical page

There are several other options for how to mark a link as canonical:

  • rel=canonical tag - Add this tag with the canonical link in the code for duplicate pages.
  • rel=canonical HTTP header - Send a rel=canonical header in your page response.
  • Sitemap - Define canonical URLs in a sitemap.
  • 301 redirect - Set us 301 redirects to indicate the page for Googlebot if the duplicate page is out to date.


To enhance a website's search engine rankings, it's essential to add canonical URLs in Magento 2.

Duplicate content can harm SEO, but using canonical tags can prevent that. Googlebot determines the canonical URL based on page content, so choosing the correct one is crucial.

Common types of duplicate content in Magento 2 include similar product and category pages, CMS pages, printer-friendly page versions, and tracking parameters in URLs.

To add canonical URLs, website owners must insert the rel="canonical" HTML tag in the correct section of each page's HTML code. The steps to add cannibal urls in Magento are shown in this article.

Get more information about the Magento platform on our Magento Tutorials section.

Nikita S.
Nikita S.
Lead Technical Writer

As a lead technical writer, Nikita S. is experienced in crafting well-researched articles that simplify complex information and promote technical communication. She has expertise in cloud computing and holds a specialization in SEO and digital marketing.

Get the fastest Magento Hosting! Get Started