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"]
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论