我的项目中曾经有两个.htaccess文件,我们有以下目录。
MainProject/
.htaccess //first .htaccess
public/
.htaccess //second .htaccess
这些项目过去运行得很好,但一旦我卸载并安装了apache,一切都变了。
这是.htaccess1:
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
这是.htaccess2:
RewriteEngine On
RewriteCond %{REQUEST_URI} !/public/* [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
我激活了mod_rewrite模块。
如果我在地址栏上写:
http://myproject.lan/
它把我带到了主页,这意味着.htaccess1运行得很好。
但当我写这样的东西时:
http://myproject.lan/login
它不起作用,并且显示一条"找不到页面"的消息。
当项目工作时会发生什么,/login=$1,所以,它会查找public/login(在.htaccess1中)
然后,在公共目录中,服务器执行第二个.htaccess,其中$1与/index.php匹配?url=/login,最终发送到前端控制器,等待处理并转换为现有路由。
如果我需要在Apache上启用某些功能,请告诉我,因为我一开始就忘记了以前是如何实现的。
感谢
您的/public/.htaccess
应该是这样的:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [L,QSA]
问题是在此中存在RewriteCond %{REQUEST_URI} !/public/* [NC]
条件。htaccess
我刚刚找到了我的问题的解决方案,问题是在我的中
httpd-vhosts.conf
我忘记将/public
添加到DocumentRoot。
感谢