_redirects not working on live with Gatsby, triggers 404

How can I debug a failing redirect proxy?

  • I am building with Gatsby
  • I put the _redirects file (with one line) in /static
  • The redirect file ends up in /public which is the dir that is served
  • Locally, I cd /public and run netlify dev, I can use the proxy and see the output in the terminal
  • I deploy to the Netlify servers, the redirect is created (I can see at the top of the deploy log)
  • The redirect doesn’t work when I hit the URL, the Gatsby 404 is returned

I think you’re going to have to supply more information for anyone to help you.

Are you certain that the file to which you are redirecting exists in the location you are specifying?

I’m not sure that I can provide much more information - I’m unsure what to do to debug redirects.

The redirects file ends up in the correct location when building on local. It runs correctly when I run the netlify dev server locally.

I am as certain as I can be that the file ends up in the correct place on the server. It says that 1 redirect is created, which is what I would expect.

Is there a way I can inspect the Netlify configuration that my build generates, so I can check that the redirect has applied correctly?

I don’t use Netlify CLI, but the docs make it sound as though the netlify dev command is run for the project, not for the build folder, but I could be way off.

At any rate, have you downloaded the deploy from Netlify to see what files are being put where?

The dev command works when I run it on the build folder from the project, as that’s the folder that will be server.

I haven’t downloaded the deploy. Is there a web interface to do that? (Thanks!)

Yes, on the deploys page, right next to the time stamp for the deploy.

I’ve done this - I can see the _redirects file, and the 1 rule that I expect is in there.

I also tried creating a rule in the Netlify.toml.

The deploy said that two rules are now applied (one from the toml, and one from _redirects), the site still serves up a 404.

Unsure of what to do next!

OK, but what about the file to which you are redirecting? Is that where you expect it to be?

Yes, it’s an external service. The service is callable from the wider internet.

The reason I’m proxying via the _redirects file is to solve CORS issues, and migrating services ‘under the hood’.

It’s the same URL that I can hit when running Netlify CLI on my local machine. Using Postman I can hit the URL on the local machine, and wider internet. It’s just when hitting it via Netlify that I get our 404 page.

This process would be easier if you would share all the information needed to help you.

Have you tried using 200 or 200! proxy? Would it be possible for you to reveal your site URL? Would it be possible for you to reveal the contents of your redirect file?

I have tried both 200 and 200!

I can’t reveal the site URL, as it’s not launched yet. The _redirects file contains 1 line:

/api/PostcodeGeo/:splat https://www.example.com/api/PostcodeGeo/:splat 200!

So this 1 line is picked up by the Netlify build process. When I add it to the Netlify.toml file, it then says 2 redirects are there, as expected.

The local run using the Netlify dev CLI correctly performs the proxy. On Live I get our 404 page.

What other information is useful?

Have you tried:

/api/PostcodeGeo/* https://www.example.com/api/PostcodeGeo/:splat 200!

Agree with Greg here - :splat is only usable as a DESTINATION, * would be the source :slight_smile:

Thanks for your help - I have added

/api/PostcodeGeo/* https://www.example.org/content/api/PostcodeGeo/:splat 200!

On the deployment URL, when I hit:


…I still get our 404 page. I have download the deployment and verified that the _redirects file contains only this line. Strange that it works locally and performs the proxy, but not in the cloud. Any other ideas?

I thought I should post an update here, now that the issue has been resolved. Maybe this will be useful for anyone searching for an answer to a similar problem.

The issue we had was:

  • We were developing a new website, migrating to Netlify / Gatsby
  • Our old website was still live at the original domain
  • We assigned the domain to our account when setting it up, but had not switched the DNS to point to Netlify
  • When trying to route the proxy to our currently live (old) website, Netlify first looks up the account to see what domains are mapped to it, bypassing the DNS
  • This meant that in looking for example.org/api/myService, Netlify recognised example.org as a site that it served. It did not check the DNS and go to the currently live site. This meant that it searched for that route locally, serving up our new 404 page when that route was not found.

So to resolve this, I used a different URL to proxy through to our API service. Another resolution would be to have removed the domain from the account until we were ready to go live.

Thanks to @fool and @gregraven for your help above. It’s appreciated!