二级 .htaccess 不工作

2nd Level .htaccess not working

我以前在我的项目中有两个 .htaccess 文件,我们有以下目录。

 MainProject/
      .htaccess        //first .htaccess
      public/
         .htaccess     //second .htaccess

项目过去工作正常,但一旦我卸载并安装了 apache,一切都变了。

这是 .htaccess 1 :

RewriteEngine On
RewriteRule ^$ public/     [L]
RewriteRule (.*) public/ [L]

而且,这是 .htaccess 2:

RewriteEngine On
RewriteCond %{REQUEST_URI} !/public/* [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url= [L,QSA]

我激活了mod_rewrite模块。

如果我在地址栏写:

http://myproject.lan/

它将我带到主页,这意味着 .htaccess 1 工作正常。

但是当我写这样的东西时:

http://myproject.lan/login

它不起作用,它显示 "page not found" 消息。

项目运行时发生的事情是 /login = $1 ,因此,它会查找 public/login(在 .htaccess 1 中)

然后,在public目录下,服务器执行第二个.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= [L,QSA]

问题是此 .htaccess

中存在 RewriteCond %{REQUEST_URI} !/public/* [NC] 条件

我刚刚找到了我的问题的解决方案,问题是在我的

httpd-vhosts.conf

我忘记将 /public 添加到 DocumentRoot。

谢谢