Redirects not being processed in production, works fine locally

I’ve got a Netlify site that supports redirects just fine locally, but when I deploy, they do not work. Also, the build log says: No redirect rules processed

I’ve confirmed the file is checked into source. The only possible thing I can imagine is that I’ve also got netlify.toml being used, but I do not specify any redirects there. Also, the docs on file based configuration (File-based configuration | Netlify Docs) do not say that files like _redirects will be ignored. As it works fine in ntl dev, I’d expect it to work in production too.

Any ideas?

@cfjedimaster Have you verified the existence of the _redirects file at the top level of your site by downloading the deploy?

So I added the redirect rule to netlify.toml and it works. So it appears we’ve got a few things here:

  • Should you be able to use both _redirects and netlify.toml? If so, than it’s a bug.
  • If not, I don’t believe the doc I linked to says you can’t mix them. It just says why netlify.toml may be better, but it doesn’t come out and say if you use both, it will be ignored.
  • Also if not - ntl dev should not process _redirects if netlify.toml exists.

If support can confirm this is expected, I can file bugs on the second two items.

Hi @cfjedimaster

Yes you can use both _redirects and netlify.toml.

Rules in the _redirects file are always processed first, followed by rules in the Netlify configuration file.
~ Redirects and rewrites | Netlify Docs

Thank you, I do now see it documented, but I am still not seeing this behaving properly in production. Locally, I added a second test to _redirects:

/api/*	/.netlify/functions/:splat	200
/index2.html	/index.html

My netlify.toml has:

  functions = "./functions"
  # command = "npm run build"
  # publish = "_site"


Notice I have /api twice, that’s because of what I said before, when I went to production the value in _redirects didn’t work.

Anyway, I added my second rule and confirmed that locally, I could ask for index2.html and get redirected to index.hml. I just deployed, and once again the report says only ONE redirect was found:

And I confirmed I can’t hit index2.html in production.

Status 200 tells the browser that the HTTP response is A ok, use 301 or 302.

What does that have to do with the issue I described above though? As I said - the redirect works locally, not in production and the log reports one rule.only, not three.

Status 200 tells the browser that the response is ok, hence, we are done now, nothing more to load. Status 301 and 302 tells the browser, specifically, that this is a redirect.

If it’s the issue, I don’t know, that the status is wrong and does absolutely nothing but cause possibly headache, that’s for sure.

Local dev servers always work differently then in production mode, to account for thousands of scenarios and different setups. That it works locally and not in production does not mean “Something is wrong with production”, it usually means “You’ve implemented something the wrong way”.

@cfjedimaster Have you downloaded your deploy to verify that the _redirects file is at the top level of your files and that it contains the instructions you think it does?

It is perfectly fine to use a 200 status and not a 301/302 if you are proxying and not redirecting as per the example from Exploring Netlify Redirects : 404s rewrites and proxies by @philhawksworth

  from = "/api/activity"
  to = ""
  status = 200

Using your simple _redirects and netlify.toml configurations @cfjedimaster I see this:

so when I go /api/hello the basic hello.js function is loaded and when I go to index2.html the index page is loaded.

Hi, @cfjedimaster. My best guess is that the file _redirects is not in the publish directory when the deploy finishes. If it is in the base directory, it won’t be processed. It must be in the publish directory at the end of the deploy to work.

I just checked the deploy with 60aa978933d29300071a0cf7 and there was no _redirects file found. This is my best guess as to the deploy where you are testing. If you are testing on some different site or deploy, please send me the deploy id and I’ll be happy to check again.

Besides not being processed, the redirects look to be correct otherwise. I do think once the file is processed, they will work as expected.

Ahhh dangit, that’s the second time that’s gotten me, and that was it. I added _redirects to Eleventy’s config to copy over. Odd that it worked locally though. Does ntl dev use the root of the project and production use the root of the output instead?

To clarify, the existence of netlify.toml in the root of the project is enough for it to work - it does not have to be copied to the output. But _redirects does. Is there a reason for that?

hi @cfjedimaster - i don’t have direct answer for you on that - i would suggest you review the issues on here: GitHub - netlify/cli: Netlify Command Line Interface

and if there is no issue on the topic, please do file a new one so that the dev/cli team can take a look and verify that this behaviour is expected (or not). thanks!