.htaccess在此服务器上找不到请求的url/public/索引



你好,我刚刚完成了服务器和所有代码文件的设置,但我遇到了问题。每当我去https://www.frindse.com/index它给我一个错误,说找不到/public/index文件。

我的网站的设置方式是,所有请求都进入公共文件夹,该文件夹包含我的index.php文件,该文件路由我的所有页面。不是在我的本地服务器上,一切都能完美地工作,但在我的digitalocean服务器上,每当我转到索引页面时,它都无法工作。但如果我去https://www.frindse.com/login页面加载完美。这就是我的.htaccess文件在我的公用文件夹中的样子,它路由我所有的页面和请求:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

这里还有.htaccess文件,它在我的网站的根目录中。它将所有呼叫路由到公用文件夹:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    public/    [L]
    RewriteRule    (.*) public/$1    [L]
 </IfModule>

还要记住,我在服务器上激活了mod_rewrite,并且我在digitaloceans服务器中将AllowOverride设置为All。

尝试在公用文件夹中的.htaccess中添加一个重写库。并关闭多视角。

Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

实际上,为什么你甚至需要一个.htaccess文件在公共文件夹中?只需将请求直接路由到根目录中的索引文件.htaccess文件,然后删除公用文件夹中的文件。

    Options -MultiViews
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -l
    RewriteRule ^ - [L]
    RewriteRule ^$ public/ [L]
    RewriteRule ^(.*)$ /public/index.php?url=$1 [QSA,L]
    </IfModule>

最新更新