Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite problem

         

fzx5v0

9:38 pm on Oct 2, 2007 (gmt 0)

10+ Year Member



I have all my dynamic urls rewriten to static urls for all my product in my database.

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}

g1smd

10:44 pm on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The ? on the end will clear the 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).

jdMorgan

1:44 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Three suggestions:

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]


Modification to pattern of your existing first RewriteRule -- Example only, this may not be correct for your URLs:

RewriteRule ^(([^-]+-)+)p-([^.]+)\.html$ product_info.php?products_id=$3&%{QUERY_STRING} [L]

The new pattern reads, "one or more characters not a hyphen, followed by a hyphen, and one or more repeats of that, all 'saved' into $1, followed by 'p' and a hyphen, followed by one or more characters not a period (saved into $3), followed by a literal period and ending with 'html'"

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