Support Forums

Netlify Redirects - Can't redirect pages that exist from build, only works for pages that don't exist

We have a client’s site hosted on Netlify, built using Gatsby.

Netlify server redirects seem to work fine for pages that don’t exist on the site, but for whatever reason we can’t get pages that do exist on the site to server side redirect to another page on the site.

Using __redirects file on Netlify, but believe we also tried on the .toml as well.

For example our build outputs “https://www.cousinsmainelobster.com/products/stick-of-butter/” which we’d really like to redirect to “https://www.cousinsmainelobster.com/products/the-at-home-lobster-roll-kit/”. The only way we were able to accomplish this so far is with a client side redirect, which isn’t ideal for SEO.

Wondering if anyone else has been able to redirect away from pages that actually exist in the site, or if static files will always be served before redirects are processed on Netlify.


If you want to force a redirect to happen even if a page exists, you have two options.
In your _redirects file

/from-here    /to-here    301!    # 302 if temporary

or in your netlify.toml

  from = "/from-here"
  to   = "/to-here"
  status = 301  # 302 if temporary
  force = true

See Redirects - Syntax for the Netlify configuration file (! in _redirects is the equivalent to force = true in netlify.toml)