开发者

a generic .htaccess regex to get every parameter

Let's say I have a domain www.stackoverflow.com I want to write an .开发者_StackOverflow中文版htaccess through which I will be table to get every parameter that is passed into URL. For e.g.

Case 1 www.stackoverflow.com/test

Case 2 www.stackoverflow.com/test/page

Case 3 www.stackoverflow.com/test/page/anotherpage

Normally I would write it this way:

RewriteRule ^([a-z0-9-]+)$ index.php?param1=$1 [NC,L]

But this will only work for Case 1 above so for Case 2 and 3 I have to write two separate lines like this:

RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)$ index.php?param1=$1&param2=$2&param3=$3 [NC,L]

RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)$index.php?param1=$1&param2=$2 [NC,L]

As you can see this can be problematic when parameters grow. So is there a generic regex that will work for all cases?

Thanks


Yes - use . instead of [a-z0-9-], and then have your index.php parse the parameters for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜