Removing canonicalisation on a site with Gatsby and Netlify

17 replies
Last updated: May 6, 2020
How can we remove canonicalisation on a site? Is there any global setting for this?
AI Update

The concept of "canonicalisation" or canonical URLs isn't something you can globally disable in Sanity itself—it's actually a frontend implementation concern, not a CMS feature.

Here's what you need to understand:

What Are Canonical URLs?

Canonical URLs are HTML <link> tags (typically <link rel="canonical" href="https://example.com/page">) that you add to your page's <head> section. They tell search engines which version of a page is the "preferred" one when you have duplicate or similar content at multiple URLs. According to Sanity's canonical URL glossary, they help prevent duplicate content issues and consolidate SEO signals.

How to "Remove" Canonicalisation

Since canonical tags are added in your frontend code (not in Sanity), here's how to remove them:

1. Check Your Frontend Templates

Look in your page templates where you render the <head> section. Common places include:

  • Next.js: pages/_document.js, app/layout.tsx, or individual page components
  • Gatsby: gatsby-ssr.js or page templates
  • Other frameworks: Your HTML template files

2. Remove the Canonical Tag Code

Find and remove code that looks like this:

// Example in Next.js
<Head>
  <link rel="canonical" href={canonicalUrl} />
</Head>

Or in your SEO component/plugin that might be generating these tags automatically.

3. Check SEO Plugins

If you're using an SEO plugin or package (like next-seo, react-helmet, or a Sanity SEO plugin), you may need to:

  • Remove the canonical URL field from your Sanity schema
  • Update your SEO component to not render canonical tags
  • Check plugin configuration to disable canonical URL generation

Important Considerations

Before removing canonical tags, be aware that:

  • They're generally considered an SEO best practice
  • Removing them won't harm your site, but you'll lose the benefits of consolidating duplicate content signals
  • If you have no duplicate content issues, canonical tags won't hurt anything (pages should self-reference their own canonical URL)

If You're Using Gatsby + Netlify

Since your search results mentioned "Gatsby and Netlify," check:

  • Your Gatsby gatsby-config.js for SEO plugins
  • Page templates in src/templates/
  • Any custom SEO components
  • Your site's <head> rendering logic

There is no global Sanity setting to disable canonicals—you control this entirely in your frontend code. If canonical tags are appearing on your site, they're being added by your frontend implementation, not by Sanity itself.

Let’s keep the conversation in this thread! 🙌
I think what
user S
is getting at is that this is probably something that has to do with how Gatsby or the hosting provider (Netlify?) deals with URLs
Since server forces trailing slash, we’ll go along with that
I just want to find out how to remove canonicalisation
Could it be that the default setup of Gatsby forces non-trailing slash urls and canonicalises the ones with trailing slash?
This is a bit hard to say without knowing your implementation of Gatsby (it's not something that comes from Sanity). But my educated guess is that there is a
<link rel="canonical" ...>
tag inserted on these pages? There is plugins for Gatsby that let you control this, for example https://www.gatsbyjs.org/packages/gatsby-plugin-react-helmet-canonical-urls/
Thanks, I’ll check out the plugin
Normally, all the links have canonical element and they canonicalise to themselves by default (at least on all the other platforms/cms’es that I worked with), but for some reason, in this case they were pointing to another version of url, and that’s what I am trying to kill 🙂
user B
were you able to get this resolved? I didn't know exactly would could be causing it but it made more sense to me that it was coming from Gatsby rather then Sanity. If you did find a fix I would love to hear more about it if possible.
Not yet, waiting for one developer to take a look into it. Will keep you posted.
Thank you so much. The other thing that could be an issue is an outdated site map. I am sure someone checked that though. I had a heck of a time with Google Tag Manager integration with Gatsby I am happy to share that fix if you would like too. Might help you down the road.
Here is the Tag Manager Integration I followed and was able to get it working. https://medium.com/nadjib-benna%C3%AF/integrate-google-tag-manager-to-a-gatsby-js-project-2dab4606749f
Thank you, we’ll look into it!
Oh last thing too. If you happen to use Netlify like we do this is how you go about it there. I saw you mention you had another host but it's worth mentioning if you are using this service for the build https://docs.netlify.com/routing/redirects/redirect-options/#http-status-codes
Yes, we do use Netlify
Thanks again, your advice is highly appreciated!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?