Forum Moderators: phranque

Message Too Old, No Replies

request support on 301 redirect

         

hyper1

6:42 am on Feb 27, 2010 (gmt 0)

10+ Year Member



We recently migrated our ecommerce site from one cart to another. The old cart had .aspx file extensions, the new one has a 3rd party SEO module that rewrites product page urls with .html and no extention on category pages (categories end with a forward slash). Our .htaccess file has the "RewriteEngine On" command to support the 3rd party mod.

I added a couple of redirect 301 commands to test my ability to redirect some of the old site urls to the new site. This is an example of one I added.

redirect 301 /apple-accessory-C92.aspx http://www.example.com/apple-accessory/

The redirects work great but I have thousands to redirect, so I have been researching forum posts for a solution. While trying to come up with a general expression to redirect additional pages from the old site to the new, I found an recent post that said it is not good practice to have both RewriteRule and Redirect commands in the same htaccess file.

So, I tried

RewriteRule /apple-accessory-C92.aspx http://www.example.com/apple-accessory/ [R=301]

This did not work, and instead of redirecting to the /apple-accessory/ url it goes to my 404 page. I also tried to use a regular expression based on what I found in the forums. A typical product url from the old site looks like this...

www.example.com/apple-accessory-P10023.aspx

I want all the products with "apple-accessory-" in the url to be directed to the /apple-accessory/ category page. I tried the following redirect statement, but like my example above, I get redirected to the 404 error page.

RewriteRule /apple-accessory-.*\.aspx http://www.example.com/apple-accessory/

This is my first attempt at a regular expression and so far, no luck. Any suggestions would be greatly appreciated.

My apologies for such a long post, I hope I do not wear out my welcome on post 1.

[edited by: jdMorgan at 4:40 pm (utc) on Mar 1, 2010]
[edit reason] Please use example.com [/edit]

g1smd

6:57 pm on Feb 27, 2010 (gmt 0)

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



RewriteRule cannot see the leading slash of the URL path.

You need an L flag with your R=301 to complete the set.

Your first guess was very close.

Yes, do not mix Redirect and RewriteRule in the same file.

The redirect target URL must include the protocol and domain name.

Avoid using .* in the pattern, there's something better like [^.]+ or similar that will be more efficient.

hyper1

9:50 pm on Feb 27, 2010 (gmt 0)

10+ Year Member



Thank you very much for the response. I am very new to regular expressions. I was intrigued by the suggestion to use [^.]+ instead of *.

If I understand correctly from your response your recommendation will require less resources from the server to process. I updated the .htaccess file with your recommendation and it works great.

Thanks again.

g1smd

11:42 pm on Feb 27, 2010 (gmt 0)

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



The new pattern can be evaluated from left to right in one pass, rather than using many 'back off and retry' trial matches when .* is used.