Laravel 默认路由到 404 页面 [英] Laravel default route to 404 page

查看:44
本文介绍了Laravel 默认路由到 404 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Laravel 4 框架并且我已经定义了一大堆路由,现在我想知道所有未定义的 url,如何将它们路由到 404 页面?

I'm using Laravel 4 framework and I've defined a whole bunch of routes, now I wonder for all the undefined urls, how to route them to 404 page?

推荐答案

未定义的路由会触发 SymfonyComponentHttpKernelExceptionNotFoundHttpException 异常,您可以在 app/start/global 中处理该异常.php 使用 App::error() 方法,如下所示:

Undefined routes fires the SymfonyComponentHttpKernelExceptionNotFoundHttpException exception which you can handle in the app/start/global.php using the App::error() method like this:

/**
 * 404 Errors
 */
App::error(function(SymfonyComponentHttpKernelExceptionNotFoundHttpException $exception, $code)
{
   // handle the exception and show view or redirect to a diff route
    return View::make('errors.404');
});

这篇关于Laravel 默认路由到 404 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆