問題背景:今天在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