Hi! I’d like to setup netlify in a way that, when a param is present, it should take me to the preview server.
Like this: GET /home Will take me to the normal homepage
but GET /home?preview=true will take me to https://www.test.com/home
I tried with this rule /* preview=true https://www.test.com/:splat 200
And it kinda works.
If I visit any non-existing page, it does the redirection correctly and as expected.
But if the route matches a page that actually exists, it won’t redirect, just show the file.
Here are the examples: https://distracted-jepsen-ca33fe.netlify.com/hello Will show 404, because the page doesn’t exist. https://distracted-jepsen-ca33fe.netlify.com/hello?preview=truewill successfully take me to www.test.com/hello https://distracted-jepsen-ca33fe.netlify.com/test naturally takes me to an existing page as expected
But here’s my problem: https://distracted-jepsen-ca33fe.netlify.com/test?preview=true Still takes me to the existing page, doesn’t do the redirect.
Good catch! Also I am not sure your formatting is quite right - I think you should be using /* preview=:preview https://www.test.com/:splat 200! for best results. We don’t have any way of evaluating the VALUE of the parameter while choosing to proxy or not, just the PRESENCE of the parameter.
Yup, that will work as you’re expecting (however without the “!” on the end of the second 200, it will only work for FILES NOT PART OF YOUR DEPLOY ALREADY!
See Redirects and rewrites | Netlify Docs for more details about what the “!” means and why if you want it on one of those rules…you probably want it on both