【问题标题】:Laravel 5.8 showing 404 Not Found errorsLaravel 5.8 显示 404 Not Found 错误
【发布时间】:2019-03-02 18:56:30
【问题描述】:

我将 index.php 文件路径 public 更改为 root。在根路径(laravel 5.7)中添加 .htaccess 文件后,每个页面都可以正常工作。但是在 laravel 5.8 中,当我点击另一个页面时,它显示 404 Not Found。

我的 .htaccess 文件在下面。

<IfModule mod_rewrite.c>

Options +FollowSymLinks

RewriteEngine On
#Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d``
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule> 

【问题讨论】:

    标签: laravel-5 laravel-5.8


    【解决方案1】:

    Laravel .htaccess 文件的内容应该是这样的:

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
             Options -MultiViews -Indexes
        </IfModule>
    
        RewriteEngine On
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    

    您的 webroot 必须设置为 /public 目录。不要尝试搜索将 index.php 和 .htaccess 文件从 /public 移动到 Laravel 应用程序根目录的其他解决方案。绝对没有理由将 webroot 从 /public 移动到 /。 index.php 位于 /public 是有原因的。如果您的虚拟主机不提供将 Web 根目录移动到另一个目录的功能,请切换您的主机。

    【讨论】:

      【解决方案2】:

      可能是您已将文件夹创建为示例并尝试通过示例访问它 即

      localhost/Example/public
      

      但是像访问它一样

      localhost/example/public
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-18
        • 2015-05-31
        • 2021-03-07
        • 1970-01-01
        • 2016-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多