开发者

Mod_Rewrite Question

How can I turn the following URL example 1 to example 开发者_StackOverflow社区2 using mod_rewrite?

Example 1

http://www.example.com/cat/index.php?cat=fruit&sub1=apple&sub2=green

Example 2

http://www.example.com/cat/fruit/apple/green/


Use something like this:

RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ index.php?$1=$2&sub1=$3&sub2=$4 [NC]

$1, $2, $3 and $4 represent the four matched groups (.*)

If there is a variable number of subcategories, you should change your strategy:

RewriteRule ^(.*)/(.*)/(.*)/$ index.php?$1=$2&subcat_string=$3 [NC]

And parse the subcat_string manually (example in python):

# subcat_string will be something like "apple/green"
subcats = subcat_string.split("/")
# subcats is now ["apple", "green"]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜