Brent Friar
Brent Friar

Reputation: 10609

HTACCESS 301 redirect URL with query string with no request URI

I have a site that has a bunch of URLs indexed in Google that look like this -

http://www.domain-namr.com/?option=filter&option2=&option3=

I am trying to redirect all of these to a new URL in HTACCESS with this code -

RewriteCond   %{REQUEST_URI}    ^/$
RewriteCond   %{QUERY_STRING}   ^option=filter$
RewriteRule   ^(.*)$ /new-url.html [R=301,L]

Of course it is not working. On all of the pages that have a filename I can use in the request uri condition, the redirects work. What am I missing?

Upvotes: 1

Views: 926

Answers (1)

anubhava
anubhava

Reputation: 784958

It is not working due to the wrong regex pattern in your rule.

Try this rule as your very first rule in root .htaccess:

RewriteCond %{QUERY_STRING} ^option=filter(&|$) [NC]
RewriteRule ^$ /new-url.html? [R=301,L]

Upvotes: 1

Related Questions