Regular expression – delete parameters using MOD_REWRITE

I want to use mod_rewrite to delete a specified query parameter from the URL.

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 Is a tricky question, because var2 = anything can appear anywhere in the query string

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]

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5424 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.