Laravel default route to 404 page

前端 未结 5 602
离开以前
离开以前 2021-02-08 08:51

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?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-08 09:29

    Undefined routes fires the Symfony\Component\HttpKernel\Exception\NotFoundHttpException exception which you can handle in the app/start/global.php using the App::error() method like this:

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

提交回复
热议问题