Forum Moderators: phranque
The URL is made up of the product name. As some of the product names have changed i would like to rewrite the url so I remove any duplicate content that i my creat by changing the product name as this will creat a new url and both of them would work
my .htaccess is at the bottom
everytime I try and rewrite
RedirectMatch 301 /original-inkjet-printer-cartridge-c9361ee-black-p-331.html /original-inkjet-printer-cartridge-c9361ee-colour-p-331.html
it adds a?products_id=331 to the end of the url why is this and how do I stop it
thanks in advance
RewriteEngine On
RedirectMatch 301 /original-inkjet-printer-cartridge-c9361ee-black-p-331.html /original-inkjet-printer-cartridge-c9361ee-colour-p-331.html
RewriteBase /
RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pi-(.*).html$ popup_image.php?pID=$2&%{QUERY_STRING}
RewriteRule ^(.*)-t-(.*).html$ articles.php?tPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-a-(.*).html$ article_info.php?articles_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pr-(.*).html$ product_reviews.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pri-(.*).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-i-(.*).html$ information.php?info_id=$2&%{QUERY_STRING}
RedirectMatch 301 /original-inkjet-printer-cartridge-c9361ee-black-p-331.html /original-inkjet-printer-cartridge-c9361ee-colour-p-331.html?
You ought to include the target domain name in the redirect, so as to force the domain to be the correct one (www vs. non-www).
First, replace your RedirectMatch directive with a RewriteRule, so that you can control the order of execution. Put the new RewriteRule first in your list.
Second, use the [L] flag on each rule so that mod_rewrite will stop processing for the current pass whenever a RewriteRule is invoked.
Third, use more specific regular-expressions patterns to prevent unexpected results and inefficient operation.
Replacement for RedirectMatch:
RewriteRule ^original-inkjet-printer-cartridge-c9361ee-black-p-331\.html$ http://www.example.com/original-inkjet-printer-cartridge-c9361ee-colour-p-331.html [R=301,L]
RewriteRule ^(([^-]+-)+)p-([^.]+)\.html$ product_info.php?products_id=$3&%{QUERY_STRING} [L]
This pattern, being much more specific, may be processed hundreds of times faster than an ambiguous 'floating-match' "^(.*)xyz(.*)abc$" - type pattern, depending on the number of characters in the requested URL-path.
Jim