具有多个查询字符串的站点结构(.htaccess)

时间:2013-12-12 20:46:22

标签: regex apache .htaccess mod-rewrite

所以基本上我想创建一个看起来像这样的网站结构:

/panel/optional1/optional2/optional3/optional4/

我试过以下:

RewriteRule ^panel/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$   index.php?page=panel&e1=$1&e2=$2&e3=$3&e4=$4 [L,QSA]
RewriteRule ^panel/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ index.php?page=panel&e1=$1&e2=$2&e3=$3 [L,QSA]
RewriteRule ^panel/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ index.php?page=panel&e1=$1&e2=$2 [L,QSA]
RewriteRule ^panel/([a-zA-Z0-9]+)/?$ index.php?page=panel&e1=$1 [L,QSA]

但它效果不佳。

1 个答案:

答案 0 :(得分:0)

好的,如您所知,请尝试此规则将所有4个合并到一个:

RewriteRule ^panel(?:/([^/]*)(?:/([^/]*))?(?:/([^/]*))?(?:/([^/]*))?)?/?$ /index.php?page=panel&e1=$1&e2=$2&e3=$3&e4=$4 [L,QSA]