This is a general question, not so much about my site in particular:
How does one handle redirects in _redirects for non-SSG pages? That is to say, imagine I want to hit an SSR page /something, but I have a rule /s* / 404
Can I put a rule in the _redirects file that will tell Netlify that, although there’s no file at that location, keep going, and it’ll get rendered?
I.e., I want to tell it to ignore the catch-all rule for that particular path, but right now, it seems to see that there’s no generated file at that path, and so it fires that catch-all and redirects.
Thanks for the suggestion… I’m not sure that I’m describing the situation clearly. Or maybe I’m misunderstanding something.
Specifically: I have a page in a Next.js site: /pages/thispage.tsx, let’s say.
That page has a getServerSideProps and so isn’t statically generated.
Now, if I have a rule in my _redirects like /t* / 301… it’ll fire when I request that file because it’s not SSG, and therefore “not there”. It’ll then get caught by the wildcard.
The solution that you’re proposing if I understand it is to use a rewrite, but… how would I do that in that case? It’s not a function. Seems like /thispage /thispage 200 would loop.
So, I’d like to just say that or something like (this is made up) /something 200 and have _redirects know that it’ll be there and it should just step off and let nextjs handle it.
It does seem entirely possible to forward /t* /somethingotherthing 301 but that will, indeed, catch my path and redirect it. Not what I wanted.
The answer is that you simply cannot redirect it that way. The _redirect stuff happens first. It just doesn’t work like that. So, you have to work around it. You could, in fact, set up a bunch of /ta*, /tb*… redirects and not /th*, if you REALLY needed to have those catch-alls.
I ended up doing something different, which just rendered this point moot, as they say, but I thought I’d follow up just to clarify that as far as I can tell, yes, you can use patterns, and either your thing is there, rendered, or _redirects is going to consider it fair game and redirect it if you have a pattern that matches.
Contrary to my previous statement, /t* /somethingotherthing 301 will work as you point out, but as you also point out, it will catch everything that starts with a t and for most uses it not ideal.