Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite 1000s of redirects

REGEX help needed

         

lixy

4:53 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



This is my situation. I have a site that ran on Xcart 3.4.5 for the longest time and 1000s of HTML catalog pages have been included by Google over the years. I recently upgraded to Xcart 4.1.3 and completed a site redesign whereby all PHP pages forward to their HTML counterpart. I am using and want to continue using the Xcart 4.1.x HTML catalog naming convention because I assume it is more search engine friendly but please correct me if I am wrong.

Basically I want to use MOD_REWRITE to dynamically 301 redirect any of the old HTML catalog links to their new Xcart 4.1.x equivalent.

PRODUCT REDIRECT
OLD = ./catalog/product_1234_Big_Red_Widget.html
NEW = ./catalog/Big-Red-Widget-p-1234.html

SINGLE PRODUCT REDIRECT
RewriteRule ^/catalog/product_1234_Big_Red_Widget\.html$ /catalog/Big-Red-Widget-p-1234.html [R=301,L]

CATEGORY REDIRECT
OLD = ./catalog/category_99_Widgets_page_1.html
NEW = ./catalog/Widgets-orderby0-p-1-c-99.html

SINGLE CATEGORY REDIRECT
RewriteRule ^/catalog/category_99_Widgets_page_1\.html$ /catalog/Widgets-orderby0-p-1-c-99.html [R=301,L]

Basically what I am looking for is a REGULAR EXPRESSION to use in the category redirect and the product redirect but I am lost when it comes to REGEX. Could anyone offer up some advice as to what each redirect statement should look like using a REGEX to address all instances of product redirects in a single statement and all instances of category redirects in a single statement.

jdMorgan

12:54 am on Oct 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's an example category redirect to get you started.

RewriteRule ^/catalog/category_([0-9]+)_([^_]+)_page_([0-9]+)\.html$ http://example.com/catalog/$2-orderby0-p-$3-c-$1.html [R=301,L]

I'm not 100% sure of the relationship between "page_1" and "p-1", but nevertheless, this code can serve as an example to get you started. We do not support "write my code for me" requests here, but if you want to learn how to do this yourelf, we will be glad to help.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

JonW

1:35 am on Oct 20, 2006 (gmt 0)

10+ Year Member



A simple solution.

I've had as many as 15,000 simple 301 redirects in .htaccess with no problems receiving 2000 hits per day on the redirected urls.

Not as elegant as regex, but might work in your situation.

lixy

6:21 pm on Oct 20, 2006 (gmt 0)

10+ Year Member



jdMorgan thank you for your help and kind advice. I defiantly want to learn and understand the solution to my problem but I think like so many out there I am absolutely baffled when it comes to REGEX. THank you again!