1

As an extension of a previous post I have the following url:

test/example/example/index.html?t=Audi&p=Petrol

but I would like a rewrite rule to strip out the query-string t and p. Note that there may be other querystring values that may be passed and these should not be stripped.

2 Answers 2

2

Try:

# First remove the t=something
RewriteCond %{QUERY_STRING} ^(.*)(^|&)t=[^&]+(.*)$
RewriteRule ^(.*)$ /$1?%1%3 [N]

# Next remove the p=something
RewriteCond %{QUERY_STRING} ^(.*)(^|&)p=[^&]+(.*)$
RewriteRule ^(.*)$ /$1?%1%3 [L]

So going to http://domain/test/example/example/index.html?a=b&t=fooo&d=f&p=barr&e=r will result in the URI getting rewritten to: /test/example/example/index.html?a=b&d=f&e=r

Sign up to request clarification or add additional context in comments.

Comments

0

Something like this:

RewriteRule ^/(.*)\&t=[a-zA-Z]+(.+)$ %1%2 [L]

Or use some RewriteCond if you need to collect that params, ie. though ENV.

1 Comment

Well "Something like this:" will not work as RewriteRule does NOT work with query string like that -- only via RewriteCond.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.