laravel 当路由不存在时重定向laravel 4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19201305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:31:15  来源:igfitidea点击:

redirect when route doesn't exist laravel 4

phplaravellaravel-4

提问by Tobias Hagenbeek

I'm using laravel 4 and when i have my project in production mode, i get "Sorry, the page you are looking for could not be found." when i hit a non existing route...

我正在使用 laravel 4,当我的项目处于生产模式时,我收到“抱歉,找不到您要查找的页面”。当我遇到一条不存在的路线时...

When i grep my code it's found in two places:

当我 grep 我的代码时,它可以在两个地方找到:

./vendor/symfony/debug/Symfony/Component/Debug/ExceptionHandler.php:129:                $title = 'Sorry, the page you are looking for could not be found.';
./vendor/symfony/debug/Symfony/Component/Debug/Tests/ExceptionHandlerTest.php:52:        $this->assertContains('Sorry, the page you are looking for could not be found.', $response->getContent());

No i would like to specify a route to handle 404's, but can't seem to find how to do this...

不,我想指定一条处理 404 的路由,但似乎无法找到如何执行此操作...

And the can someone maybe explain why it's using symfony error handling and where setting for that can be found?

有人可以解释为什么它使用 symfony 错误处理以及在哪里可以找到它的设置吗?

回答by The Alpha

You may register an error handler that handles all "404 Not Found" errors in your application, allowing you to return custom 404 error pages:

您可以注册一个错误处理程序来处理应用程序中的所有“404 Not Found”错误,从而允许您返回自定义 404 错误页面:

App::missing(function($exception)
{
    // return Response::view('errors.missing', array(), 404);
    return Redirect::to('someurl');
});

Check documentation.

检查文档。

Also, Laraveluses some Symphony componentsto simplify the development process of some core functionality of it's framework, including routing, response and many more.

此外,Laravel使用一些Symphony 组件来简化其框架的一些核心功能的开发过程,包括路由、响应等。