Home
Support Forums

Trouble with query parameter in a redirect

Hello to everyone,
I’m trying to create a redirect with query parameter, but it won’t work.

I’m trying to achieve this:

example.com/js.html?q=123 -> example.com/test/123

My _redirects file:
/js.html q=:q /test/:q 200

Could someone help me? Thank you.

Ok, fixed. I just added this rule:
/* /js.html 200

edit: Not working.

/* id=:id  /test/:id  301

this should work.

Edit: Just saw your own reply, just to be clear that you are redirecting the user so a 200 could be misinformation to search engines etc. I personally think a 301 should be used to provide the correct information?

1 Like

Thanks for the solution. I think the code status 200 is appropriate, because search engines didn’t index this URL. But I might be mistaken.

edit: Your solution is also not working.
edit 2: Not working, because I’m using pushState.

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.

I think the issue was acknowledged by the user as using pushState since it doesn’t not refresh the page and just changes history stack, therefore wouldn’t trigger the redirect, just change URL