【发布时间】:2017-09-20 21:18:48
【问题描述】:
我用 laravel 5.4 制作了简单的简历网站,如果用户输入除我的网站名称和我的 site.com/panel 之外的任何内容,我想自动重定向到 404 页面。
我该怎么做?
有什么途径可以做到吗?
我找到了这段代码,但没有使用
public function render($request, Exception $e)
{
if ($e instanceof
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException){
return response(redirect(url('/')), 404);
}
return parent::render($request, $e);
}
【问题讨论】:
-
根据文档“创建一个
resources/views/errors/404.blade.php。此文件将在您的应用程序生成的所有 404 错误中提供。” -
感谢 man.it 工作 :)
-
@linktoahref 是对的,我只是将正确的链接添加到 Laravel 5.5 文档 laravel.com/docs/5.5/errors 和完整引用:
Laravel makes it easy to display custom error pages for various HTTP status codes. For example, if you wish to customize the error page for 404 HTTP status codes, create a resources/views/errors/404.blade.php. This file will be served on all 404 errors generated by your application. The views within this directory should be named to match the HTTP status code they correspond to.
标签: php database laravel controller routes