开发者

Combining multiple htaccess rewrite rules into one

开发者 https://www.devze.com 2022-12-17 16:34 出处:网络
First, let me say this: I suck at regex and htaccess. I\'m trying to make a rule that will properly parse url segments into variables. So far I have this:

First, let me say this: I suck at regex and htaccess. I'm trying to make a rule that will properly parse url segments into variables. So far I have this:

RewriteRule ^([^/]+)/?$ index.php?query[]=$1 [QSA,L]
RewriteRule ^([开发者_运维技巧^/]+)/([^/]+)/?$ index.php?query[]=$1&query[]=$2 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?query[]=$1&query[]=$2&query[]=$3 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?query[]=$1&query[]=$2&query[]=$3&query[]=$4 [QSA,L]

It works, sort of, but I feel it's longer than it needs to be; and what if I want 5 or 6 or 7 variables? Is there a more condensed way to write this out?

Also, when I spit out the query array, the first element is always index.php. What's up with that?


Don't use RewriteRule to convert pathinfo to query parameters, but just enable MultiViews in Apache HTTP Server and use $_SERVER['PATH_INFO'] in index.php with little help of explode().

0

精彩评论

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