我有以下RewriteRule代码
RewriteRule ^(.*)/(.*)/(.*)$ /page.php?menu=$1&submenu=$2&submenu2=$3 [L,QSA,NC]
RewriteRule ^(.*)/(.*)$ /page.php?menu=$1&submenu=$2 [L,QSA,NC]
RewriteRule ^(.*)$ /page.php?menu=$1 [L,QSA,NC]
我需要它做什么:
如果网址类似于mydomain.com/test
,请转到mydomain.com/page.php?menu=test
如果网址类似于mydomain.com/test/site
,请转到mydomain.com/page.php?menu=test&submenu=site
如果网址类似于mydomain.com/test/site/stuff
,请转到mydomain.com/page.php?menu=test&submenu=site&submenu2=stuff
但这些似乎相互冲突。
我知道如何改进它以使其发挥作用。
答案 0 :(得分:0)
保持这样的规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /page.php?menu=$1&submenu=$2&submenu2=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ /page.php?menu=$1&submenu=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ /page.php?menu=$1 [L,QSA]