首页 > 解决方案 > Apache - 使用 .htaccess 重定向到根文件夹

问题描述

我的.htaccess文件有问题。我以这种方式配置它。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)/$ index.php?controller=$1 [L]

每次我http://localhost/mvc3/contacto/访问 http://localhost/mvc3/index.php?controller=contacto时,它都是正确的,但是如果友好的 URL 我删除了最后一个字符/ http://localhost/mvc3/contacto,它会将我返回到根页面(wampserver 服务器)。

这是问题的视频中的解释,会发生什么?

视频▶️ http://recordit.co/FfXHww1xCv

标签: php.htaccess

解决方案


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?controller=$1 [L]

从重写规则中删除斜线,它应该可以工作。


推荐阅读