_redirects seems to be ignored, redirects not working

I am experiencing issues getting my redirections to work. I am sure they worked at one point, but recently I think they completely stopped. This is a little bit more complicated setup, bear with me :wink:

Netlify ID: kollitsch-dev.netlify.app
Deployed at : https://kollitsch.dev
Git repo at GitHub - davidsneighbour/kollitsch.dev: Content and website setup for kollitsch.dev

I am building my site with GoHugo and deploy via Netlify CLI. A normal deploy can be tested with the following command chain:

cd repo
npm install
npm run deploy

The deploy command will update and build the site, then deploy. The script is here.

I can confirm, that in my public folder AFTER the build is a _redirects file with the following content:

################################################################################
# Netlification v1.2.4
################################################################################
/blog/2022/notes-from-the-laboratory-february-2022 /blog/2022/notes-from-the-laboratory-february/
/blog/2022/notes-from-the-laboratory-january-2022 /blog/2022/notes-from-the-laboratory-january/
/*                                       /404.html                                404
https://kollitsch-dev.netlify.app*       https://kollitsch.dev/:splat             301!
/repos/*                                 https://kollitsch.dev/                  
/2005/*                                  https://kollitsch.dev/                  
/2006/*                                  https://kollitsch.dev/                  
/2007/*                                  https://kollitsch.dev/                  
/2008/*                                  https://kollitsch.dev/                  
/tags/kollitsch.de/                      https://kollitsch.dev/tags/kollitsch.dev/
/tags/dnb/                               https://kollitsch.dev/tags/davidsneighbour/
/repos/textpattern-plugins/current/      https://kollitsch.dev/                  

The first two redirects miraculously work, none of the other redirects actually work (ending up on the the 404 redirect that I got from the Netlify docs).

What could be the issue? It feels like the file is not parsed for “special” redirects with * and stops after an error?

I also read in many responses here to check, if the file is actually on the site. I can’t :wink: When I load https://kollitsch.de/_redirects it shows a file not found page. I know it’s in the public directory, but I don’t see a mention of parsed redirects in the netlify deploy command. I tried deploying via Git-hook - same result.

As I understand it the redirect rules are processed from top to bottom.

The 404 one is effectively saying "anything that doesn’t exist should end up at /404.html.

It may not make a difference, but the https://kollitsch-dev.netlify.app one looks like it should be:

https://kollitsch-dev.netlify.app/*       https://kollitsch.dev/:splat 

All the rules further down are 301 redirects by default, without force, so…

  • If the content does exist then it’ll just get returned in place, since they’re not being forced
  • If the content doesn’t exist it’ll already be getting handled by the 404 rule above

You might want to try moving your 404 rule to the bottom of the file, and adding 302! to your other rules (for testing purposes), later switching them out to 301! once you’ve got everything sorted.

1 Like

Thank you, fixing the slash and moving the 404 at the end did the trick. I would expect some form of error message or warning though when deploying… it might help to know, that after a certain line the file is seemingly not read anymore, be it by syntax error or a catchall that is overzealous.

Thanks for your help!

1 Like

There is a playground that you can test rules with here:
https://play.netlify.com/redirects

But you’ll find that if you insert all your original rules that it says “Yay! All redirects are valid”.

2 Likes

Glad everything is working now, @davidsneighbour! Thank you for the super clear and helpful steps here, @nathanmartin :netliconfetti:

1 Like