Example:
1) User enters the URL:
http://localhost/intra/page.htm?var1=123&var2=456&var3=789
2)mod_rewrite delete “var2 = 456”
< p>3) New URL:
http://localhost/intra/page.htm?var1=123&var3=789
My question is, I only know the parameter name (var2), not the value (456),
and I update to understand the order of the parameters. It may be at the beginning and end of the query string.
I would appreciate any help , Because I spent a lot of time searching online and didn’t find any effective solutions.
This code should work for you:
< pre>Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.+?&|)var2= [^&]*(?:&(.*)|)$[NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,L]
< /p>
I want to use mod_rewrite to delete a specified query parameter from the URL.
Example:
1) User input URL:
p>
http://localhost/intra/page.htm?var1=123&var2=456&var3=789
2)mod_rewrite delete “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), not the value (456 ),
And I updated to understand the order of the parameters. It may be located at the beginning and end of the query string.
I would appreciate any help, because I spent a lot of time searching online and did not find any Effective solution.
This is a tricky problem, because var2=anything can appear anywhere in the query string
< /p>
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]