user2693302
user2693302

Reputation: 61

301 Rewrite Rule Not working

We want to redirect Below mentioned URL.

From URL:

www.example.com/itemLevelFilterPage.action?keyWordTxt=&srchTyp=CATNAV&attrFilterList=attr_brand%3A%223M%22&resultPage=0

To URL : www.example.com/4G

We wrote 301 rules in apache configuration as below.

RewriteEngine on  
RewriteRule ^/itemLevelFilterPage.action?keyWordTxt=&srchTyp=CATNAV&attrFilterList=attr_brand%3A%223M%22&resultPage=0  /4G   [L,R=301]

But redirection is not working as expected. Any Suggestion will be highly appreciated.

Upvotes: 0

Views: 180

Answers (1)

miken32
miken32

Reputation: 42770

mod_rewrite will not look at query strings as part of its matching, unless you specifically ask it to:

RewriteCond %{REQUEST_URI}  ^/itemLevelFilterPage\.action$
RewriteCond %{QUERY_STRING} ^keyWordTxt=&srchTyp=CATNAV&attrFilterList=attr_brand%3A%223M%22&resultPage=0$
RewriteRule (.*)            http://www.example.com/4G?  [R=301,L]

The first condition makes sure we're looking at the right page, the second checks the query string, and the rule will rewrite the URL to the desired one.

The trailing question mark on the rule ensures the old query string is removed. If you're on Apache 2.4 the query string discard flag is available:

RewriteRule (.*)            http://www.example.com/4G  [R=301,L,QSD]

More examples here.

Upvotes: 2

Related Questions