multiple parameter condition

Discuss practical ways rearrange URLs using mod_rewrite.

multiple parameter condition

Postby jonnyd91 » Sun Nov 23, 2008 9:28 pm

RewriteRule ^(.*)products/(.*)/(.*)$ $1/products?BRAND=$2&VENDORCODE=$3 [PT,L]

Hi, I am currently using the above rule to make this ure:
http://www.testsite.com/products?BRAND=?&VENDORCODE=471

look like this:
http://www.testsite.com/products/ALIFE/248

Sometimes the url will have a 3rd parameter like below:

http://www.testsite.com/products?BRAND= ... 71&offset=?

I need a rule or condition to change the above to the below url when &offset=? is being passed in:

http://www.testsite.com/products/ALIFE/248/1

thanks
john
jonnyd91
 
Posts: 13
Joined: Sun Nov 16, 2008 9:46 pm

Postby richardk » Mon Nov 24, 2008 1:11 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(.*/)?products/([^/]+)/([^/]+)(?:/([0-9]+))?/?$ $1products?BRAND=$2&VENDORCODE=$3&offset=$4 [PT,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jonnyd91 » Mon Nov 24, 2008 8:30 pm

for some reason i get an 500 internal server error when i go to the initial url

www.mysite.com

can i put both of these in:

RewriteRule ^(.*)products/(.*)/(.*)$ $1/products?BRAND=$2&VENDORCODE=$3 [PT,L]
RewriteRule ^(.*)products/(.*)/(.*)/(.*)$ $1/products?BRAND=$2&VENDORCODE=$3&offset=$4 [PT,L]

would it know to go to the one with the extra parameter when clicking that url?
jonnyd91
 
Posts: 13
Joined: Sun Nov 16, 2008 9:46 pm

Postby richardk » Tue Nov 25, 2008 4:24 am

You can use two rules
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(.*/)?products/([^/]+)/([^/]+)/?$          $1products?BRAND=$2&VENDORCODE=$3           [PT,L]
RewriteRule ^(.*/)?products/([^/]+)/([^/]+)/([0-9]+)/?$ $1products?BRAND=$2&VENDORCODE=$3&offset=$4 [PT,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: Google [Bot] and 22 guests

cron