Moved Site - Need Rewrite Help

Using mod_rewrite to handle various content issues

Moved Site - Need Rewrite Help

Postby rotokirby » Tue Jun 17, 2008 4:35 pm

We've recently moved our e-commerce site to a new server and different software. I'm attempting to use Mod-Rewrite to do 301 Redirections for old URLs but I just can't get the hang of it.

Old Server was Apache...New Server is Windows Server 2003

We have Micronovae's IIS Mod-Rewrite Pro v3 installed on the new server.

Here's what we need (there are a few different scenarios):

--------

Base URL

Original URL:
http://domain.com/Merchant2/merchant.mvc

Should Redirect to:
http://domain.com/toyscart/pc/

-------

Content Pages

Orignal URL Example:
http://domain.com/Merchant2/merchant.mv ... _Code=RDTS

Should Redirect to:
http://domain.com/toyscart/pc/viewcontent.asp?idpage=6

(about 10 specifc URLs that need to Redirect to specific new URLS)

------

Product Categories

Original URL Example:
http://domain.com/Merchant2/merchant.mv ... _Code=SALE

Should Redirect to:
http://domain.com/toyscart/pc/viewCateg ... Category=3

(about 20 specific URLS that need to redirect)

-------

Product Pages

Original URL Example:
http://domain.com/Merchant2/merchant.mv ... y_Code=NEW

Should Redirect to:
http://domain.com/toyscart/pc/showsearc ... it=Search+

(grabbing the SKU from the original URL and using it to search the new site for that SKU)


Thanks in advance if anyone can help! :D
rotokirby
 
Posts: 4
Joined: Tue Jun 17, 2008 4:24 pm

Postby richardk » Thu Jun 19, 2008 1:19 pm

The basics for Apache mod_rewrite, to match a query string parameter (key=value)
Code: Select all
RewriteCond %{QUERY_STRING} ^(.*&)key=value(&.*)?$ [NC]

if you want to use the value
Code: Select all
RewriteCond %{QUERY_STRING} ^(.*&)key=([^&]+)(&.*)?$ [NC]

and %2 will equal "value". To match the file and put the new URL
Code: Select all
RewriteRule ^file$ /new-url-%2-can-be-used-here? [R=301,L]


Try
Code: Select all
RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^Merchant2/merchant\.mvc$ /toyscart/pc/? [R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?Screen=ABOUTUS(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?Store_Code=RDTS(&.*)?$ [NC]
RewriteRule ^Merchant2/merchant\.mvc$ /toyscart/pc/viewcontent.asp?idpage=6 [R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?Screen=CTGY(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?Store_Code=RDTS(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?Category_Code=SALE(&.*)?$ [NC]
RewriteRule ^Merchant2/merchant\.mvc$ /toyscart/pc/viewCategories.asp?idCategory=3 [R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?Screen=PROD(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?Store_Code=RDTS(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?Category_Code=NEW(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?Product_Code=([^&]+)(&.*)?$ [NC]
RewriteRule ^Merchant2/merchant\.mvc$ /toyscart/pc/showsearchresults.asp?idcategory=0&idSupplier=10&priceFrom=0&priceUntil=999999999&sku=%2&IDBrand=0&keyWord=&customfield=0&SearchValues=&resultCnt=12&order=2&Submit.x=44&Submit.y=7&Submit=Search+ [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rotokirby » Fri Jun 27, 2008 11:10 am

Thanks so much for the suggestion Richard. I'll see if I can get it working. :)
rotokirby
 
Posts: 4
Joined: Tue Jun 17, 2008 4:24 pm

Postby rotokirby » Sun Jun 29, 2008 4:08 am

Unfortunately, this doesn't seem to be doing anything. :(

I can confirm that Mod-Rewrite is working because we're using it to remove requests for www.domain.com with the following ReWrite rule, which works:


Code: Select all
# Remove WWW from URL
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [R=301,L]


Unfortunately, that seems to be the only rule that is doing anything.

Currently we have IIS doing a permanent redirect of all requests for "Merchant2/merchant.mvc" to a custom error page, but even if I turn off that redirect the Mod-Rewrite rules other than the one cited above don't seem to do anything.
rotokirby
 
Posts: 4
Joined: Tue Jun 17, 2008 4:24 pm

Postby richardk » Mon Jun 30, 2008 12:10 pm

Try replacing all
Code: Select all
^Merchant2

with
Code: Select all
^/Merchant2
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rotokirby » Tue Jul 01, 2008 8:17 am

Working now!

Richardk....I have no idea where you are, but if you're ever in Chicago I owe you a drink! Thank you so much for the help.
rotokirby
 
Posts: 4
Joined: Tue Jun 17, 2008 4:24 pm


Return to Content

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests

cron