php - Cakephp 403错误不显示自定义页面

标签 php .htaccess cakephp cakephp-2.0 http-status-code-403

当导航到 mysite.com/img 中的位置(转换为 app/webroot/img)时,我收到标准 apache 403 错误页面。

我正在使用 Cakephp 2.x 并设置了自定义 error400.ctp,据我测试,它可以正确处理 404 错误。

这是一个 htaccess 问题,没有让 cakephp 处理错误吗?如何在不硬编码 .htaccess 中的路径的情况下显示 error400.ctp 页面?

这是我的 app/webroot .htaccess 文件

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

谢谢!

最佳答案

在您的 AppController 中编写以下代码。

function beforeFilter() {
    if($this->name == 'CakeError'){
        $this->layout = 'error400';
    }
}

这适用于所有蛋糕错误。

关于php - Cakephp 403错误不显示自定义页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18028547/

相关文章:

javascript - 使用 iframe 中的按钮重新加载父窗口

.htaccess 与 url 缩短器

php - 当有内容配置时,如何提取邮件正文?

php - CakePHP - 使用不同的数据源动态加载模型

java - php exec() & java 发送参数

php - 从 mysql 查询创建数组。 Column2 作为键 Column 1 作为值

php - 使用 PHP Regex 编辑 CSS 文件

php - 架构MVC脚本

.htaccess:如何使用 .htaccess 使用 no-follow、do-not-index 指令永久重定向动态地址

CakePHP:如何在 app_controller 中使用模型