开发者

Help with creating mod_rewrite rules?

I am looking for your help on for writing mod_rewrite URL for the below URL

mywebsite.com/cars.php?model=GM&make=Pontiac&year=2009

I want to access the above URL using

mywebsite.com/cars/GM/Pontiac/2009

and the last tw开发者_如何学Pythono parameters are optional ..

Could somebody please advise ?

Regards

Kiran


Assuming we're in the document root:

RewriteRule ^cars/([a-zA-Z0-9]+)$ cars.php?model=$1 [L,QSA]
RewriteRule ^cars/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ cars.php?model=$1&make=$2 [L,QSA]
RewriteRule ^cars/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/(\d+)$ cars.php?model=$1&make=$2&year=$3 [L,QSA]

This enforces a strict ordering, i.e. the arguments are expected to be "model, "make" and "year" in that order.

You probably also want to add:

RewriteRule ^cars/?$ cars.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜