使用以下规则我将匹配模式的网址 domain.com/Controller/Action
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?Controller=$1&Action=$2 [L]
RewriteRule ^([^/]+)/?$ index.php?Controller=$1&Action=Index [L]
当我打电话给 domain.com/Foo/Bar 时,请求变量是
Array ( [Controller] => index.php [Action] => Index )
我错在哪里?此外,我怎么能不匹配任何参数?
答案 0 :(得分:1)
您需要添加重写条件以避免重写真实文件/目录:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?Controller=$1&Action=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?Controller=$1&Action=Index [L,QSA]