views:

211

answers:

1

I have a pretty complex RewriteRule where I need to check if certain parameters are present in QueryString and then redirect to the same URL but with those parameters stripped.

How can I remove some parameters and preserve the rest?

RewriteCond %{QUERY_STRING} color=red
RewriteCond %{QUERY_STRING} status=contiue
RewriteRule ^(.*)$ /$1? [R=301,L]

url is like:

"http://example.com/site.php?setup=done&color=red&weight=100&status=continue"

(parameters order and quantity is not predictable/hardcoded)

A: 

Try these rules:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)(color=red|status=continue)($|&)(.*)
RewriteRule .* $0?%1%5 [N,E=REMOVED:true]
RewriteCond %{ENV:REMOVED} true
RewriteRule ^ %{REQUEST_URI} [L,R=301]

Another way would be to use PHP to check what parameters are given and remove them there.

Gumbo