“The requested URL / was not found on this server“和laravel路由不显示index.php以及laravel报错419的解决方案

问题背景:今天在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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值