laravel-5 - Laravel 5.8 显示 404 Not Found 错误
问题描述
我将 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 .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 根目录移动到另一个目录的功能,请切换您的主机。
推荐阅读
- php - 如何获取 AWS PHP 开发工具包以查找我存储在 Elastic Beanstalk 环境变量中的凭证?
- java - Jenkins 有没有办法检查我的 Java 代码是否是谷歌风格的格式,并且只有在格式正确的情况下才通过构建?
- sql - 您如何使用数据框、列表、向量等过滤到 R 中数据库中的表?
- python - 方格内空心方格
- java - VScode Java/Maven环境问题不同电脑
- android - 与文本内联的 React-native 图标
- ios - 将 int ([3,6]) 数组转换为 [[1,2,3],[1,2,3,4,5,6]]
- python - Jupyter 文件打开未出现在新文件列表中
- excel - 将文件夹中的 .xlsx 文件保存为 .csv 文件
- python - 在 Python 中使用 Pywinauto 在特定按钮上按 Enter