Issue with URL rewriting for user friendly URLs

Discuss practical ways rearrange URLs using mod_rewrite.

Issue with URL rewriting for user friendly URLs

Postby mamin123 » Mon Sep 01, 2008 11:53 am

Hi,
I have following URL and I am struggling to make it work. I am very new to this and any help will be greatly appreciated:

1)Age:

If user enters

http://mysite.com/Toys-For-Age-0-1-Years-old-Kids-page2.htm

then I need this URL to rewrite in

http://mysite.com/ShowbyAge.asp?Age_From=0&Age_To=1&curpage=2

OR

http://mysite.com/ShowbyAge.asp?Age_From=0&Age_To=1

I have below rule but it is causing issue with extra "OPTIONAL" parameter (Curpage=2 2 is variable) whic is not always there
Code: Select all
RewriteRule ^(.+)/*-(age)-(\w+)\.htm$ /ShowByAge.asp?Age_From=$3 [NC]

===========================================================================================
b) Vendor:
If user enters

http://mysite.com/creativity-for-kids-v-cfk-page2.htm

then I need this URL to rewrite in

http://mysite.com/ShowbyVendor.asp?VendorID=CFK&Curpage=2

OR

http://mysite.com/ShowbyVendor.asp?VendorID=CFK

I have below rule but it is causing issue with extra "OPTIONAL" parameter (Curpage=2 2 is variable) whic is not always there
Code: Select all
#Vendor URL
RewriteRule ^(.+)/*-(v)-(\w+)\.htm$ /ShowbyVendor.asp?Vendorid=$3 [NC]

===========================================================================================
c)
If user enters

http://mysite.com/Alex-Craft-Scissors-p-Af413.htm

then I need this URL to rewrite in

http://mysite.com/viewproduct.asp?Productid=Af413[/b]

Code: Select all
# From URL: /Alex-Craft-Scissors-P-Af413.htm and TO URL will be /viewproduct.asp?Productid=Af413
#Product URL
RewriteRule ^(.+)/*-(p)-(\w+)\.htm$ /viewproduct.asp?productID=$3 [NC]


Above code works fine but it is causing issue when I have below URL
http://mysite.com/Alex-Craft-Scissors-p-Af-413.htm

===========================================================================================

[/b]Any other idea to improve any possible issue and make URL better will be always welcome[/b]
mamin123
 
Posts: 2
Joined: Mon Sep 01, 2008 11:05 am
Location: USA

Postby richardk » Tue Sep 02, 2008 11:48 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^.+-age-([0-9]+)-([0-9]+)-.+-page([0-9]+)\.htm$ /ShowbyAge.asp?Age_From=$1&Age_To=$2&curpage=$3 [NC,QSA,L]
RewriteRule ^.+-age-([0-9]+)-([0-9]+)-.+\.htm$              /ShowbyAge.asp?Age_From=$1&Age_To=$2            [NC,QSA,L]
RewriteRule ^.+-v-([^-]+)-page([0-9]+)\.htm$                /ShowbyVendor.asp?VendorID=$1&Curpage=$2        [NC,QSA,L]
RewriteRule ^.+-v-([^-]+)\.htm$                             /ShowbyVendor.asp?VendorID=$1                   [NC,QSA,L]
RewriteRule ^.+-p-(.+)\.htm$                                /viewproduct.asp?Productid=$1                   [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 9 guests

cron