问题背景:今天在postman运行本地项目的时候,遇到三个问题
1:"The requested URL / was not found on this server"的问题:
2:laravel路由不显示index.php
3:laravel报错419的解决方案
经过一番查阅之后
总结了一下原因
1:是localhost指向的问题,只需要定义正确localhost的指向正确位置就可
2:路由可以跳过index.php,不过需要在apache上进行配置
3:"419 Sorry, your session has expired. Please refresh and try again."需要禁用禁用csrf
解决方案
1:定义localhost时候,只需要在apache 的 "httpd.conf" 检查DocumentRoot 是指向哪里的
比如laravel则需要定义到 /htdocs/pinpaiVip/public 这个路径才算正确
2:路由跳过index.php,只需要在apache 的 "httpd.conf" 检查所有AllowOverride ,将后面的none改成All
3:方案一:在"Kernel.php"文件夹里面把\App\Http\Middleware\VerifyCsrfToken::class,这句注释了,不引用这个校验文件
方案二(来自网友,亲测也可行):更改文件:./app/Http/Middleware/VerifyCsrfToken.php源文件内容如下,禁用csrf
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
use Closure;
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'http://localhost/*', //新增字段
];
}
参照https://blog.csdn.net/GorgeousChou/article/details/86508582