Laravel 修改404页状态码 防止页面被劫持

来源:互联网 发布:编程书籍推荐 编辑:程序博客网 时间:2024/06/16 05:19

由于网络环境复杂和各种APP的劫持,404页面就会被替换为第三方的页面。
下面介绍一种简单粗暴的在Laravel中修改404页状态码的方法。


在目录\resources\views\errors\编写404视图文件并命名为404.blade.php

打开位于\vendor\laravel\framework\src\Illuminate\Foundation\ 目录下的Application.php文件
在第925行添加代码die(view('errors.404'));

修改前

public function abort($code, $message = '', array $headers = []){    if ($code == 404) {        throw new NotFoundHttpException($message);    }    throw new HttpException($code, $message, null, $headers);}

修改后

public function abort($code, $message = '', array $headers = []){    if ($code == 404) {        die(view('errors.404'));        throw new NotFoundHttpException($message);    }    throw new HttpException($code, $message, null, $headers);}
原创粉丝点击