htaccess将多行减少为一行?

时间:2012-06-05 09:23:59

标签: .htaccess

我有一个.htaccess文件,其中包含以下规则:

RewriteRule ^(boards)/(.+)/(.+)/(.+)/(.+)/([^./+])/?$ index.php?param0=$1&param1=$2&param2=$3&param3=$4&param4=$5&param5=$6 [NC]

RewriteRule ^(boards)/(.+)/(.+)/(.+)/([^./]+)/?$ index.php?param0=$1&param1=$2&param2=$3&param3=$4&param4=$5 [NC]

RewriteRule ^(boards)/(.+)/(.+)/([^./]+)/?$ index.php?param0=$1&param1=$2&param2=$3&param3=$4 [NC]

RewriteRule ^(boards)/(.+)/([^./]+)/?$ index.php?param0=$1&param1=$2&param2=$3 [NC]

RewriteRule ^(boards)/([^./]+)/?$ index.php?param0=$1&param1=$2 [NC]

RewriteRule ^(boards)/?$ index.php?param0=$1 [NC]

我的问题:是否可以将这些组合成一个规则?这样维护真是太烦人了......

1 个答案:

答案 0 :(得分:1)

如果您可以修改index.php,则可以执行以下操作:

RewriteRule ^boards/(.*) index.php?url=$1 [NC]

并在$_GET['url']内解析index.php

更好的是,你可以做到

RewriteRule ^boards/.* index.php [NC]

然后在$_SERVER['REQUEST_URI']中自己解析index.php