/ Published in: Apache
                    
                                        
Great little bit of code for if you are rewriting URLs but then want the old GET URLs to rewrite to their rewritten URLs (phew). Good for telling Google where the new pages are with a 301 rather than getting both indexed.
In this example, i had a page for casual menswear which was 'www.domain.com/product_list.php?cat=3' but i rewrote this URL to be 'www.domain.com/casual' only problem is that because they both still existed Google still had the '?cat=3' page indexed as the casual page, so this bit of code 301 redirects anyone wanting the '?cat=3' to the new '/casual' page.
                In this example, i had a page for casual menswear which was 'www.domain.com/product_list.php?cat=3' but i rewrote this URL to be 'www.domain.com/casual' only problem is that because they both still existed Google still had the '?cat=3' page indexed as the casual page, so this bit of code 301 redirects anyone wanting the '?cat=3' to the new '/casual' page.
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
RewriteRule ^casual?$ product_list.php?cat=3 [L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?cat=3(&.*)?$ [NC]
RewriteRule ^product_list\.php$ /casual? [NC,R=301,L]
Comments
 Subscribe to comments
                    Subscribe to comments
                
                