Greetings again @Jennifer_G!
I’m sorry to hear that you had issues! Can you elaborate on those? And just in case, does your site run any service workers? Those can be a real tricky thing with caching… Also what version of NextJS are you running?
Debugging the trailing slash stuff should be doable locally as well — just run a full
netlify build from your local command line and inspect the resulting publish directory (maybe run a
clean first just in case). You should expect to see any page on any path throughout the site to be a folder with the page name and an
index.html contained therein with all the page content. That’s a good first verification step.
The 404 page is actually the one place that we don’t want the trailing slash premise of “take the page and make it an
index.html inside a named folder” to take place. Netlify automatically takes note if your site has the specifically-named
404.html page in the publish directory and automatically serves it as the 404 page instead of Netlify’s own. This is why https://jonsully.net/foo looks the way it does. I use Gatsby, but Gatsby generates a
404.html in the publish directory for me and Netlify serves it on any 404-resulting request.
Now that said, I’m really not sure if there’s any way to get NextJS to force trailing slashes for everywhere except
404.html. If it can’t, I’d say either use the
_redirect with shadowing like you tried, or just make a custom
404.html (outside of Next.js) and make sure it gets copied to the publish folder.
I am curious if there’s a
_redirects precedence issue going on if we setup a redirect like yours,
/* /404/ 404 then presume you have a file in your publish directory like
/public/blog/random-thing/index.html, a request to your site at example.com/blog/random-thing/ (note the trailing slash) should work fine. I’m wondering if a request to example.com/blog/random-thing (no trailing slash) is getting picked up by the 404 redirect rule instead of just pushing the user to the trailing-slash version of the route. Would need to test this, but that could account for some serious head-aches if so.
PS. just as a last fleeting thought — I wonder if you could just turn off the
trailingSlash: true, run a local export, go into the public / publish directory and copy the
404.html Next generated, paste that into your static directory, then turn
trailingSlash: back on effectively using Next to generate your
404.html page once (locally) then making sure all the trailing slash rules are enabled thereafter. If you did this you could remove the
_redirects 404 catch-all too.