Redirect rules ignored

Hi! For some reason, I can’t get redirects to work.

I want Netlify to serve links “[site].netlify.app/doc/…” as normal and redirect everything else to the home page “[site].netlify.app/”.

I tried using this _redirects file:
/doc/* /doc/:splat 200
/* / 301!

Or this netlify.toml file:
[[redirects]]
from = “/doc/*”
to = “/doc/:splat”
status = 200

[[redirects]]
from = “/*”
to = “/”
force = true

However, they both get ignored.

  • I use manual deployment, no git repo linked. I upload the website source code directly with index.html at the project’s root directory, Netlify skips building and everything else and just does post-processing, the website works as expected.
  • netlify.toml or _redirects are beside index.html in Netlify’s Deploy file browser, and contain the same above rules. Filenames correct.
  • Deploy summary says “2 redirect rules processed”, “All redirect rules deployed without errors”.
  • Pretty URLs is off, no header rules, no functions, no edge functions. I’m on the free plan.

Any idea what could be going on?

Can’t check anything unless a site is mentioned. However, this:

should be removed as it will most likely cause a redirect loop and thus might be ignored automatically.

1 Like

Thanks for the tip! I added a loop counter at the top to solve this. For some reason it was still ignored, I had to replace the root links “/” with “index.html”, which finally worked. It now looks like this:

/index.html /index.html 200!
/doc/* /doc/:splat 200
/* /index.html 301!

Which revealed a second issue I didn’t know about, which is that the script and stylesheet links in the HTML file are also redirected. I assume I must add exceptions for each of them at the top of the redirects file.

You don’t need a loop couter. You just need to remove ! from the last redirect,