开发者

URL rewriting help

I am stuck in some URL rewriting problem.

RewriteRule ^(userratings)/(.*)$ /user_rating.php?userId=$2 [L]

This is working for me.

i want to add 3rd variable also. But it might be there or not there also.

开发者_如何学C
RewriteRule ^(userratings)/(.*)/(.*)$ /abc.php?userId=$2&product=$3 [L]

but the last /(.*) can be there or not be there also . So how do i write it for such a condition?


This rule will do the job:

RewriteRule ^userratings/([^/]+)(/(.*))?$ /abc.php?userId=$1&product=$3 [QSA,L]

Test Examples:

  • /userratings/12345/hello will be rewritten into /abc.php?userId=12345&product=hello
  • /userratings/12345 will be rewritten into /abc.php?userId=12345&product=

This means, that if 3rd parameter in URL path is not present, then value of product= will be empty string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜