Canonical URLs: What Are They and Why Are They Important?

Canonical URLs: What Are They and Why Are They Important?

Canonical URLs: What Are They and Why Are They Important?SEO is important for every website, and an online store is no exception. Using canonical URLs can help to better inform search engines which URLs have identical or highly similar content.

So what is a canonical URL?

A canonical URL refers to an HTML link element, with the attribute of rel="canonical", found in the <head> element of your webpage. It specifies to search engines your preferred URL. What that means is that the canonical URL element informs Google and other search engines to crawl a website, and what URL to index that specific page content under. This is important because URLs can have variations, based on a variety of factors, but be serving up the same or similar content. The specification went live in April of 2012, and was described in RFC 6596.

Take for example the following URLs:

fancytshirts.com
www.fancytshirts.com
https://m.fancytshirts.com
https://amp.fancytshirts.com
https://fancytshirts.com?ref=twitter

Each URL is referring to the same homepage content for my fancy t-shirt website, however the URLs themselves are slightly different. This can be an issue for search engines, because the engine itself doesn’t necessarily know which page should be the source of truth, and it may just choose a canonical URL algorithmically for you.

In other words, if you have a web page accessible by multiple URLs, or different pages with similar content (ie. separate mobile and desktop versions), you should specify to a search engine which URL is authoritative (canonical) for that page.

Why do canonical URLs matter?

1. They help to specify which URL that you want people to see in search results.

    You might prefer people reach your blue t-shirts product page via:

    https://www.fancytshirts.com/tshirts/blue/bluetshirt.html

    Rather than:

    https://fancytshirts.com/tshirts/sportswear?gclid=ABCD
    2. They simplify tracking metrics for a single product/topic.

      When there are a variety of URLs, it's becomes more difficult to get consolidated metrics for a specific piece of content.

      3. They consolidate link signals for similar or duplicate pages and manage syndicated content.

        Canonical URLs help search engines consolidate the information they have for the individual URLs (such as links to them) into a single, authoritative URL. Additionally if you syndicate your content for publication on other domains, canonical URLs help to consolidate page ranking to your preferred URL. In other words, similar or duplicate content across websites won’t have to compete for traffic/ranking in search engines.

        The canonical_url object

        canonical url: object

        In Shopify, the canonical_url object returns the canonical URL for the current page. The canonical URL is the page's "default" URL with any URL parameters removed. It can be output like this:

        {{ canonical_url }}

        For Shopify products and variants, the canonical URL output is the default product page with no collection or variant selected.

        For example, a product in a collection with a variant selected might look something like this:

        https://fancytshirts.com/collections/classics/products/classic-t?variant=17287731270
        

        The canonical_url output for this page would be:

        https://fancytshirts.com/products/classic-t
        

        For specific use-cases, you can create custom canonical URLs for pages or blog posts by using if statements, based on various templates in your theme and using theme settings. This is usually only required if you are doing some fancy URL masking.

        You might also like: An Introduction to Theme Options.

        SEO considerations and best practices for canonical URLs

        canonical url: seo best practices

        Various ways to canonicalize multiple urls

        Outside of using rel="canonical" there are multiple ways to canonicalize URLs. In most cases, rel="canonical" is the recommended way of consolidating duplicate content for search engines, however here are a few other ways of canonicalization to consider.

        1. 301 Redirect
        A 301 redirect is a status code that tells Google or other search engines that you wish to create a permanent redirect from one URL to another. A 301 redirect sends visitors and search engines to a different URL than the one they originally request in their browser or click on from a search results page. These redirects also link various URLs together, so that search engines rank all of the addresses based on the domain authority from inbound links.


        2. Use Passive parameters in the Google Search Console
        In the Google Search Console, you can find the option to set URL parameters, once your website is verified. What this does is give you the ability to tell Google which parameters you would like to consider passive. What this means is that you can tell Google, “whenever you see this URL parameter, just treat it like it doesn’t exist”. There’s a great tutorial on how to set passive parameters with the URL parameters tool in Google Search Console.

        3. Use location hashes
        Also known as fragment identifiers, a fragment URL is a URL with a # at the end of it that specifies a specific section on a page (usually jumping to an id that matches the name of the fragment identifier). A hash can exist in the URL, and Google along with other search engines will consider it a single URL. This means that that jumped content won’t be ranked differently, and therefore not indexed differently - essentially canonicalized to the same URL.

          You might also like: 5 Simple Google Analytics Reports You Should Create for Every Client.

          Things to keep in mind or avoid 📝

          When playing around with SEO and canonicalization it’s important to understand fully the implications it has with search ranking. These can be both good and bad, but to avoid the bad bits, I’ve put together a few things to keep in mind when using canonical URLs.

          Canonical URL or a 301 redirect?

          Shopify creates automatic redirects for you (for example in blog posts) when you change the URL of an already published post to a new URL. However, making the choice between a 301 redirect or setting a canonical URL can sometimes be tough. According to SEO expert Joost de Valk at Yoast, “if there are no technical reasons not to do a redirect, you should always do a redirect. If you cannot redirect because that would break the user experience or be otherwise problematic, set a canonical URL”.

          If you’re looking to create manual redirects for specific pages on Shopify, you can follow this handy tutorial found in our documentation.

          Do not block Google from crawling specific URLs

          You can use robots.txt to tell Google what pages to disallow, essentially which to crawl and not to crawl. However, this is problematic when it comes to duplicate content. This is because you’re essentially telling Google not to look at a specific page, therefore Googlebot doesn’t crawl or index the page at all, which means any ranking signals that page might have had (though duplicate content), could have contributed to the original source if specified with a canonical URL. This means you miss out on engagement signals, content signals, anything that would have helped contribute to a Google ranking.

          Don’t just delete non-canonical versions 🙅‍

          Additionally with duplicate content, there is sometimes the inclination of wanting to ‘clean up’ and delete or remove old posts, products, etc. The problem with this is that sometimes that content has been linked to or referenced in other places.

          For example, someone might have saved a product on Pinterest, and will no longer be able to access it once it’s been deleted. A solution here is to instead redirect to the new page, product, etc., which should be available for potential customers. The only time it’s recommended to remove pages entirely without redirects is if they were made in error, very new, or have little to no traffic whatsoever.

          Canonical URLs for everyone!

          SEO is important for every website, and using canonical URLs can help to better inform search engines which URLs have identical or highly similar content. Get started by making sure the Shopify theme you built, or use, contains canonical URLs.

          Have you ever used canonical URLs in a project? Have some interesting stories or use cases? Share them with us in the comments below!

          Illustrations by Tiffany Tse.

          About the Author

          Tiffany is a Front End Developer Advocate Lead at Shopify. She specializes in front end development, user experience design, accessibility, and is passionate about inspiring young designers and developers. Previously, she was an Ottawa Chapter Lead for Ladies Learning Code and worked as a Front End Developer for Partnerships at Shopify.

          Grow your business with the Shopify Partner Program

          Learn more