最佳答案
/public/.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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
讨论数量:
部署《Laravel 8 中文文档》 添加伪静态了嘛
location / {
try_files $uri $uri/ /index.php?$query_string;
}
我找到了个奇怪的解决方法, 我是用的是phpstudy apache 版本:2.4.39 就是在cmd创建项目后进入编辑器添加一个路由后不能使用,但是在文件夹中删除整个项目后,再在原来的项目位置重建一个同名项目后,进入编辑器后添加路由后,就可以使用路由
你看到的 404 页面应该是 apache 服务器默认的 404 页面,如果是 laravel 找不到路由的话,你看到的页面会是 laravel 内置的 404 页面。
所以就是缺少了一步,将所有不存在的请求转发到 index.php 文件。
/public/.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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
推荐文章: