I would like to use mod_rewrite to remove a specifik query parameter from an URL.
Example: 1) User enters URL:
http://localhost/intra/page.htm?var1=123&var2=456&var3=789
2) mod_rewrite removes "var2=456"
3) New URL:
http://localhost/intra/page.htm?var1=123&var3=789
My problem is, that I only know the parameter name (var2), and not the value (456), and that I newer know the order of the parameters. It might be placed at the beginning as well as the end of the query string.
I would appreciate any help, as I used a lot of time searching the web, without finding any working solution.
Its a tricky problem since var2=anything can really appear anywhere in query string.
This code should work for you:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.+?&|)var2=[^&]*(?:&(.*)|)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With