使用mod_rewrite传递的参数错误

时间:2014-04-10 20:44:48

标签: apache .htaccess mod-rewrite

使用以下规则我将匹配模式的网址 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 )

我错在哪里?此外,我怎么能不匹配任何参数?

1 个答案:

答案 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]
相关问题