Home
Support Forums

Redirect url with one param to another url with a different param

What we’re tying to do is redirect https://www.example.com/?event=brain-and-lungs to just https://www.example.com/day-2/?event=lungs …but how does one go about this using either the _redirects or netlify.toml syntax? I’ve tried various approaches, but no luck!

hi there, before we dig in, did you see this brand new guide on debugging redirects?

I strongly suggest you give it a thorough read through and see if this fixes your problem:

if not, please post again, and we’ll try and troubleshoot.

Hi perry, yes I read that post before I posted, but couldn’t find anything relating to my issue. Is what I’m trying to do even possible with Netlify redirects? i.e. Is it possible to redirect from one url with hardcoded query params to another url with different hardcoded query params?

Yeah, it should work. Could you let us know what you’ve tried that didn’t work?

/* event=:event /day-2/?event=bar 301!

I’d advise against this redirect rule as it will lead to an infinite redirect. So, use it only for the paths you need.

Thanks for your reply hrishikesh, but I don’t see how you suggest your example should work if in the next line you advise it will result in an infinite redirect. Can you give an example with the paths and query params I asked about in my question please?

I gave you an example of the correct syntax, not an example specific to your use case. The reason it will go in infinite redirect is that, that rule matches all files in the deploy with the event parameter. And since you wish to keep the name of the parameter same in the redirected URL, it will match that path too.

Since I’m not perfectly sure about your use case, I cannot share the exact code that you need, I’ve shared the one based on assumptions on how you might want to use it.

Thanks hrishikesh, I just figured it out. In my case I had to remove the * from the homepage path at the beginning, as like you said, I was getting infinite redirects because of matches with other redirected URLs.

All good now. Appreciate your advise.

1 Like