How to fix page not found on Gatsby

Fix broken internal links pointing to pages that return a 404 error by either removing those links or setting up a 301 redirect from the missing URL to the correct replacement page.

Steps for Gatsby

  1. Audit all internal links by running a crawl (e.g. `gatsby build && npx broken-link-checker http://localhost:9000 -ro`) or using a tool like Screaming Frog to produce a definitive list of broken href values and their correct replacement URLs.
  2. For every broken URL that has a valid replacement, add a 301 redirect entry to `gatsby-config.js` inside the `siteMetadata`-level `createRedirect` calls — or, if using Gatsby Cloud / Netlify / Vercel, export them from `gatsby-node.js` using the `createRedirect` action inside `exports.createPages`.
  3. For broken links where no replacement exists, find every component or page template that renders the dead href (typically inside `src/components/` or `src/pages/`) and remove or replace the `<Link>` / `<a>` element entirely.
  4. Create a custom `src/pages/404.js` (Gatsby's built-in 404 page) so that any undiscovered broken links degrade gracefully and are surfaced clearly to users and crawlers.
  5. Re-run `gatsby build` and repeat the link audit to confirm zero 404 responses remain before deploying.
Official Gatsby documentation ↗

What is page not found?

A 404 ("Page Not Found") error means a URL on your store no longer exists — but other pages on your site still link to it. Every time a shopper or search engine follows one of those links, they hit a dead end instead of useful content. This can happen when you delete a product, rename a collection, restructure your URLs, or migrate to a new platform without properly redirecting old addresses.

Search engines like Google treat 404 pages as dead ends: any ranking authority ("link equity") that flowed through those internal links is wasted instead of boosting the destination page. Googlebot also has a limited crawl budget — time spent re-crawling broken URLs is time not spent discovering your new or best-selling pages, which can slow indexing and hurt rankings. For shoppers, clicking a link and landing on a 404 page destroys trust, interrupts the purchase journey, and directly costs you sales. If enough 404s accumulate, Google can downgrade its overall assessment of your site's quality.

See the complete Page not found guide for every platform and the full background.

Not sure if your Gatsby store has this?

Run a free SEOLZ scan — we’ll find page not found and every other issue across your whole site.

Scan my site free

Fix page not found on another platform