2
votes

Example:

1) URL (a poorly constructed one) is already indexed by Google:
www.abc.com/index.php?product=zzz

2) The URL is rewritten by using the following rewrite rule:
RewriteRule ^zzz$ index.php?product=zzz [L,NC]

The above is working fine, but we want to tell Google that the page has permanently moved from the URL in (1) URL www.abc.com/index.php?product=zzz to the URL in (2) www.abc.com/zzz

3) So now we apply the following rule above the rule (2):
RewriteCond %{QUERY_STRING} ^product=zzz [NC]
RewriteRule index http://www.abc.com/zzz? [L,R=301]

This results in an infinite loop. How do we tell Google that our site has changed from www.abc.com/index.php?product=zzz to www.abc.com/zzz? Or will Google do this by themselves?

-----Current full htaccess rules resulting in infinite loop:-----

RewriteCond %{QUERY_STRING} ^product=zzz [NC]
RewriteRule index http://www.abc.com/zzz? [L,R=301]

RewriteRule ^zzz$ index.php?product=zzz [L,NC]

1

1 Answers

0
votes

Replace your existing rules with this code:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?product=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]

RewriteRule ^(zzz)/?$ /index.php?product=$1 [L,NC,QSA]