ahnbizcad ahnbizcad - 1 year ago 67
Apache Configuration Question

Pass all other query params in apache htaccess rewrite / redirect?

I want to match certain query params, and redirect to some new url but not lose all other query params (e.g. utm, etc)

For instance if the request is


I want to redirect to




I know $1 $2 etc refer to groups of the rewrite rule,
and %1 %2 refer to groups of the query string.

The following

RewriteCond %{REQUEST_URI} ^request$
Rewritecond %{QUERY_STRING} ^(.)a=1(.*)$
RewriteRule .* /?%1%2 [L,R=302]

subtracts the
, but does not handle the & smartly.

Answer Source

You can use this redirect rule:

RewriteCond %{QUERY_STRING} ^(.*&)?a=1(?:&(.*))?$ [NC]
RewriteRule ^request/?$ /target?%1%2 [L,NE,R=302]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download