Reputation: 31
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.
Upvotes: 3
Views: 5162
Reputation: 785246
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]
Upvotes: 12