Remove trailing query string from redirected URL

Hi everyone,

I’m trying to redirect some query strings to static pages on ( My _redirects file has the following line:

/MyCap/ participantCode=:id /MyCap/:id.html 301!

But this changes the link from to I would like to convert it to (i.e. remove the query string at the end of the URL).

How do I do this?

Thanks very much!

Hi @nathhenry3

Appending the .html to the redirect isn’t valid syntax.

If (for example) there is an /about.html page on your site, this page is available via /about (no .html extension required) so changing the redirect to

/MyCap/ participantCode=:id /MyCap/:id 301!

will likely work as demonstrated in this documentation.

Thanks for letting me know about the .html issue @coelmay - I’ve fixed this now.

The redirect is now working on some devices but not in an Android webview, and I wonder if removal of the trailing query string would possibly resolve the issue. Do you know of any way to do this?


By design the redirects passes through the query string. To stop this happening, you can add a query string as demonstrated in [Support Guide] Making redirects work for you - troubleshooting and debugging

/MyCap  participantCode=:id /MyCap/:id?redir

Whether this solves the issue with Android Webview I cannot say. The only other way to remove the query string (that I am aware of) is using JavaScript on the front end.

That works. Unfortunately that hasn’t resolved the WebView issue, but I don’t think that’s any fault of yours. I just uncovered this thread showing that removal of the query string isn’t possible without Javascript yet. Hopefully this gets fixed soon.

Thanks for your help!

It does state in the documentation previously linked

…our service automatically passes on all query string parameters to destination paths for redirects…

This is handy because you can have a redirect configured, e.g.

/in    /to/somewhere

then have parameters on this URL e.g. (assuming your site is

which then get passed along automatically e.g.

This is great for redirects for affiliate links, UTM Campaign tracking etc. Along with this you can have

/in  utm_campaign=:utm_campaign  /to/somewhere?utm_source=twitter&utm_campaign=:utm_campaign

so when you use the link

this gets appended to the redirect

meaning you could use the same URL for multiple campaigns on the same platform/site (and if utm_campaign is it missing, the redirect condition fails so does not trigger.)

This is a functionality I am using with a URL shortener I have recently started working on to reduce the number of redirects required.

While I cannot (and do not) speak for Netlify, dropping this functionality isn’t something I would see as advantageous. Possibility they can work around this and offer a way of dropping the query string forwarding on a per-URL basis.

I found reference to Android Webview having issues with query strings in this post from 2012 (yes, 10 years ago!) so this is not a new thing. I also found this workaround though as I don’t partake in Android development, I cannot say if it works or is useful to your use case.