Redirects are not working as expected

Hey,

my redirects have been behaving weirdly lately and I don’t quite understand what the problem is. For the longest time (4+ years) I used the following _redirects configuration and it worked as expected:

/* /index.html 200

If you request a file lets say /sitemap.xml it would properly display the file and everything else gets redirected to the index.html as you’d expect. But at some point this has changed and Netlify started serving the .html paths even for resources that have a file behind them:

For instance lets take the /sitemap.xml

This serves /index.html, if you refresh a few times it sometimes will display the /sitemap.xml

( Can only embed one image so this one is just a link: https://i.imgur.com/TPwGPB0.png )

In an attempt to solve this I played around with changing the configuration a few times:

In this attempt (whats currently live) I decided to specifiy every route that should go to /index.html separately

/           /index.html     200
/b/*        /index.html     200
/favorites  /index.html     200
/about      /index.html     200
/settings   /index.html     200

Combined with this in my netlify.toml

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 404

So that the 404 pages keep working.

Before that I tried to hard wire the static files I cared about into it:

/robots.txt     /robots.txt     200
/sitemap.xml    /sitemap.xml    200
/data.json      /data.json      200
/meta.json      /meta.json      200
/map/names.json /map/names.json 200
/*              /index.html     200

Which also resulted in a similar outcome.

Keep in mind that I’m using the live site with Cloudflare, but I’ve been able to reproduce this on deployment previews which are not served through that CDN. So I’m certain this is not the cause of the issue either.

Unless I’m doing something wrong, this seems like an issue on Netlifys end, otherwise I’d at least hope to see a somewhat consistently broken behavior on my end :).

Best regards.

Hey @atomicptr,

Thank you for the detailed post, but looks like you missed a key detail :wink: - your site name or ID. The redirect behaviour has not changed and is working in a similar fashion for other sites, so there’s definitely something weird going on here.

Hey, the site name is “dauntless-builder” / Site ID “00d0a7c5-100f-4357-a09c-4612cc3d9879”

Hey @atomicptr,

I checked this deploy: Netlify App which seems to be the last production deploy with just 1 rediret rule - the one that you expect to work.

I visited: https://62dfea4ad947ff0009ec5349--dauntless-builder.netlify.app/sitemap.xml and the sitemap seems to load fine.

Do you have a specific deploy in which you were getting a 404 for the sitemap or other files?

Currently its broken for me on these:

And probably more

Interesting, it appears to work for me:

Thats really interesting, for me all of these show the 404 page

(Probably don’t need to make a screenshot of all of them)

Tested this with a few friends real quick and we also get mixed results, some see the XML some the 404 page

Edit: I might need to add, every time I changed something this worked again for an unknown period of time and I later noticed this being broken again. I deployed a branch with the original configuration “/* /index.html 200” to https://deploy-preview-278--dauntless-builder.netlify.app/ which right now works for me as well, although even with the current (live) one I don’t understand why this doesn’t work :thinking:.

Edit 2: Now the new build also stopped working for me :slight_smile:

I think I found the issue, kinda stupid…

What made the difference on the different systems we’ve tested this on was the fact if people used the site before or not, which will trigger the PWA to install and since that does not include the /sitemap.xml (or other files for that matter) it shows the 404 page.

Thanks for your time, it instantly working on your system raised the necessary suspensions :sweat_smile:

Thank you so much for coming back and sharing this with the forums, @atomicptr! This will help future members who encounter something similar. Happy building :rocket: