SEO audits › Gatsby

Gatsby site SEO audit

A Gatsby site ships no sitemap, robots.txt or canonical tags until you add a plugin or write them yourself, and its redirects only work if your host is told about them. This page covers each piece for the Gatsby JavaScript framework, with the config to copy.

Code is for Gatsby 5 and checked against the current docs on gatsbyjs.com. Everything here is generated at build time, so verify it on the deployed site, not in gatsby develop.

Run a free audit on your Gatsby site

All 140+ checks, no credit card. Last reviewed 2026-11-26.

Gatsby sitemap (gatsby-plugin-sitemap)

Install gatsby-plugin-sitemap, set siteMetadata.siteUrl in gatsby-config.js, and add the plugin. A production build then writes sitemap-index.xml at the site root plus sitemap-0.xml, with a new numbered file for every 45,000 URLs. The URL to submit to search engines is /sitemap-index.xml. There is no /sitemap.xml unless you create one.

The plugin only generates output in production mode, so gatsby develop will never show a sitemap. Test with gatsby build && gatsby serve.

gatsby-config.js (Gatsby 5, gatsby-plugin-sitemap)

// npm install gatsby-plugin-sitemap

module.exports = {
  siteMetadata: {
    // Required unless you provide resolveSiteUrl.
    siteUrl: `https://www.example.com`,
  },
  plugins: [
    {
      resolve: `gatsby-plugin-sitemap`,
      options: {
        // Folder the files are written to. Default is the site root.
        output: `/`,
        // Paths to leave out. Supports minimatch globs.
        excludes: [`/thank-you/`, `/drafts/**`],
      },
    },
  ],
}

By default the sitemap includes every page the build creates except the ones you exclude. /404, /dev-404-page and /offline-plugin-app-shell-fallback are always left out. Anything else you do not want indexed has to go in excludes or a filterPages function, including pages you have marked noindex.

The default output adds changefreq and priority to every URL, and the plugin's own README says those values will most likely be wrong and that Google ignores both. What is worth configuring is an accurate lastmod: pass a custom query that fetches each page's modified date and a serialize function that maps it to lastmod. The plugin README has a full example.

The sitemap URLs are built from siteUrl plus each page path, so a wrong siteUrl (http instead of https, a missing www, a preview hostname) makes every entry point at a URL that redirects. Paths also follow the trailingSlash setting in gatsby-config.js, which defaults to always. If your host serves the opposite form, every sitemap URL redirects there too.

Wrendex checks for this: Sitemap URL returns 4xx, Sitemap URL redirects, Sitemap URL is noindex, Sitemap URL non-canonical, URL missing from sitemap

Gatsby robots.txt (gatsby-plugin-robots-txt)

There are two ways to get a robots.txt on a Gatsby site. Put a hand-written file at static/robots.txt and Gatsby copies it to the site root unchanged. Or install gatsby-plugin-robots-txt, a community plugin that generates the file at build time and can write different rules per environment.

The plugin is the better choice when the same repo builds both production and deploy previews, because previews should not be crawled. Set sitemap explicitly: the plugin's documented default sitemap path is not the same everywhere it is published, and gatsby-plugin-sitemap writes to /sitemap-index.xml.

gatsby-config.js (Gatsby 5, gatsby-plugin-robots-txt)

// npm install gatsby-plugin-robots-txt

module.exports = {
  siteMetadata: {
    siteUrl: `https://www.example.com`,
  },
  plugins: [
    {
      resolve: `gatsby-plugin-robots-txt`,
      options: {
        host: `https://www.example.com`,
        sitemap: `https://www.example.com/sitemap-index.xml`,
        // The key is GATSBY_ACTIVE_ENV, then NODE_ENV, else 'development'.
        env: {
          development: {
            policy: [{ userAgent: `*`, disallow: [`/`] }],
          },
          production: {
            policy: [{ userAgent: `*`, allow: `/` }],
          },
        },
      },
    },
  ],
}

gatsby build runs with NODE_ENV=production, so a deploy preview built the normal way gets the production rules. To tell them apart, set GATSBY_ACTIVE_ENV in the preview build, or use the plugin's resolveEnv option to return your host's own context variable. The plugin README shows this for Netlify with resolveEnv: () => process.env.CONTEXT and separate branch-deploy and deploy-preview entries that disallow everything and set sitemap and host to null.

Do not use both approaches at once. A static/robots.txt and the plugin both write /robots.txt. After deploying, open /robots.txt on the production domain and confirm it is the production version: a Disallow: / that leaks from a preview config blocks the whole site.

Wrendex checks for this: robots.txt inaccessible

Gatsby canonical URLs

Gatsby adds no canonical tag by default. The quickest fix is gatsby-plugin-canonical-urls: give it your siteUrl and it adds <link rel="canonical"> to the head of every generated HTML page, built from that base plus the page path.

The plugin includes URL search parameters in the canonical by default. Set stripQueryString: true so that /blog?tag=foobar canonicalizes to /blog, unless a query parameter really selects different content.

gatsby-config.js with the plugin, or the Head API in a page (Gatsby 5)

// Option 1: gatsby-config.js
// npm install gatsby-plugin-canonical-urls

module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-canonical-urls`,
      options: {
        siteUrl: `https://www.example.com`,
        stripQueryString: true,
      },
    },
  ],
}

// Option 2: the Head API (gatsby@4.19.0 and later), in a page or template.
// src/templates/post.js
import * as React from "react"

const SITE_URL = `https://www.example.com`

export const Head = ({ location, data }) => (
  <>
    <title>{data.markdownRemark.frontmatter.title}</title>
    <link rel="canonical" href={`${SITE_URL}${location.pathname}`} />
  </>
)

Use the Head API when some pages need a canonical that is not their own URL, for example a syndicated post that should point at the original. Head can only be exported from a page or a createPage template, not from an ordinary component, and it receives location.pathname, params, data and pageContext. Pick one approach per page so you do not emit two canonical tags.

The canonical has to match the URL form the site actually serves. Gatsby's trailingSlash option (always by default, or never or ignore) controls the paths Gatsby generates, and your host decides whether /about and /about/ both resolve or one redirects to the other. If the canonical says /about/ and the host redirects that to /about, every canonical on the site points at a redirect. A crawl shows this as one issue repeated on every page.

Wrendex checks for this: Duplicates without canonical, Canonical points to redirect, Canonical points to 4xx, Non-canonical declared as canonical, Canonical https to http

Gatsby redirects (createRedirect and what your host does with it)

Call the createRedirect action in gatsby-node.js to declare a redirect. On its own that does not produce a server redirect. A Gatsby build is static files, so in the words of the Gatsby docs, redirects must be implemented by your deployment platform. createRedirect records the rule, and an adapter or plugin for your host turns it into something the host enforces.

fromPath must start with a forward slash, toPath is the destination, and isPermanent: true marks the redirect permanent. Without it the redirect is temporary, which is the wrong signal for a page that has moved for good.

gatsby-node.js (Gatsby 5)

exports.createPages = async ({ actions }) => {
  const { createRedirect } = actions

  createRedirect({
    fromPath: `/old-url/`,
    toPath: `/new-url/`,
    isPermanent: true,
  })

  // Redirects from data: for example a list of moved posts
  const moved = [
    { from: `/blog/2019/launch/`, to: `/blog/launch/` },
    { from: `/docs/v1/`, to: `/docs/` },
  ]

  moved.forEach(({ from, to }) => {
    createRedirect({ fromPath: from, toPath: to, isPermanent: true })
  })
}

What happens next depends on the host. Adapters, added in gatsby@5.12.0, take the build output and apply redirects, rewrites and headers on the platform for you. gatsby-adapter-netlify is the official one, configured through the adapter key in gatsby-config.js, and community adapters for other platforms are published on npm under gatsby-adapter. On older Gatsby versions the same job is done by a host-specific plugin.

On a plain static file host with no adapter, gatsby-plugin-meta-redirect writes an HTML file at each fromPath containing <meta http-equiv="refresh" content="0; URL='/new-url/'" />. Put it last in the plugins array. This works anywhere, but the old URL answers with status 200 and a page that redirects in the browser, not with an HTTP redirect. Google treats an instant meta refresh as a permanent redirect, but other crawlers and tools may not follow it, so prefer real server redirects when the host supports them.

Options such as statusCode, force and ignoreCase are plugin-specific: they only do something if your adapter or host plugin supports them. Keep fromPath and toPath in sync with your trailingSlash setting, or a redirect to /new-url will be followed by a second hop to /new-url/.

After a deploy, request an old URL with curl -I and confirm the status and Location header. Wrendex follows every redirect it meets and reports chains, loops, meta refresh redirects and internal links that still point at redirected URLs.

Wrendex checks for this: Redirect chain, Redirect loop, 302 temporary redirect, Meta refresh redirect, Broken redirect, Links to redirected page

Gatsby 404 page

Create src/pages/404.js and Gatsby builds it as 404.html at the site root. Any page whose path matches /404/ or /404 is treated as the 404 page, and you do not need to register it in gatsby-node.js.

Gatsby only produces the file. The 404 status code comes from your host. The file is named 404.html because many static hosts serve it with a 404 status for unknown paths by default. On any other host you have to add a rule that serves /404.html with status 404.

src/pages/404.js (Gatsby 5)

import * as React from "react"
import { Link } from "gatsby"

const NotFoundPage = () => (
  <main>
    <h1>Page not found</h1>
    <p>
      The page you asked for does not exist. <Link to="/">Go to the homepage</Link>.
    </p>
  </main>
)

export default NotFoundPage

export const Head = () => (
  <>
    <title>Page not found</title>
    <meta name="robots" content="noindex" />
  </>
)

During gatsby develop, Gatsby shows its own development 404 page that lists every page on the site, with a "Preview custom 404 page" link to see yours. To see what visitors get, run gatsby build && gatsby serve or check the deployed site.

The thing to verify in production is the status code. Run curl -I https://www.example.com/this-page-does-not-exist and confirm it says 404. A host configured with a catch-all rewrite to index.html or 404.html at status 200 turns every mistyped URL into an indexable page, known as a soft 404. The noindex in the example above is a fallback for that case.

A working 404 page does not fix the links that lead to it. Deleted pages, renamed slugs and typos in Markdown links are the usual sources on a Gatsby site, and a crawl lists each broken link with the page it was found on.

Wrendex checks for this: 404 Not Found, Links to broken page, Sitemap URL returns 4xx

Sources

Check your Gatsby site now

Wrendex crawls your site the way a search engine does and lists every issue above that it finds, page by page, with how to fix it.

Run free audit

All 140+ checks, free, no credit card.