dqu3974 2010-11-05 17:24
浏览 26
已采纳

CakePHP:将所有404错误重定向到主页?

Is there a way or a function within a controller that tells if a 404 error was triggered? I would like everyone to redirect at the homepage instead of seeing a 404 page.

Thanks!

  • 写回答

4条回答 默认 最新

  • douzhi3776 2010-11-05 18:06
    关注

    To catch and handle 404 errors, you need to extend the ErrorHandler class and override the error404 method. To do that, create the file app/app_error.php with the following code:

    class AppError extends ErrorHandler {
        function error404($params) {
            // redirect to homepage
            $this->controller->redirect('/');
        }
    }
    

    Manual

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?