Conditional rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

Conditional rewrite

Postby Guest » Mon Jan 03, 2005 9:54 pm

I have the following url's
http://somesite.com/1/
http://somesite.com/1/somecategory/
http://somesite.com/1/somecategory/3/
I need to transform this to
script.php?siteid=1&category=somecategory&page=3
I have write a pattern for this rewrite:
^([0-9]+)(/(.[^/]+)/(.[^/]+))?
But the problem is that it only recognize
http://somesite.com/1/somecategory/3/
I need to know how to make so that if i don't enter the second or the third parts of the path, to still be recognized and to assign this as null values
So if i have http://somesite.com/1/
the mod_rewrite to make it
script.php?siteid=1&category=&page=
Guest
 

Postby Caterham » Tue Jan 04, 2005 5:10 am

use
Code: Select all
^([0-9]+)/?(.[^/]+)?/?(.[^/]+)?/?$
istead :-)

(or try at least, not tested :biggrin: )

Bob
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 46 guests

cron