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条)

报告相同问题?

悬赏问题

  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥100 网页游戏在本地页面修改游戏结果
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead