Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework 带有htaccess的Zend框架_Zend Framework_.htaccess_Redirect_Error Handling - Fatal编程技术网

Zend framework 带有htaccess的Zend框架

Zend framework 带有htaccess的Zend框架,zend-framework,.htaccess,redirect,error-handling,Zend Framework,.htaccess,Redirect,Error Handling,我使用Zend框架开发了一个网站。为了处理错误,我想在htaccess文件中添加以下行,以便每次出现错误时都可以将用户重定向到相应的位置 ErrorDocument 500 /errors/500.html ErrorDocument 404 /errors/404.html ErrorDocument 403 /errors/403.html 因此,我现在在/public文件夹中的htaccess文件如下所示: RewriteEngine on # Rewrite rules for Zen

我使用Zend框架开发了一个网站。为了处理错误,我想在htaccess文件中添加以下行,以便每次出现错误时都可以将用户重定向到相应的位置

ErrorDocument 500 /errors/500.html
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
因此,我现在在
/public
文件夹中的htaccess文件如下所示:

RewriteEngine on
# Rewrite rules for Zend Framework

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

# Security: Don't allow browsing of directories
Options -Indexes
# PHP settings
php_flag magic_quotes_gpc off
php_flag register_globals off
php_flag short_open_tag on

ErrorDocument 500 /errors/500.html
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
然而,它似乎不起作用,它不会将我重定向到这些页面中的任何一个,而是显示这个经典的错误页面

服务器错误

网站在检索时遇到错误 . 它可能要停机维修了 或配置不正确

以下是一些建议:重新加载此网站 稍后再翻页。HTTP错误500(内部服务器错误):意外错误 服务器尝试实现时遇到条件 请求


有没有人想到修复我的htaccess文件,以便Apache能够正确处理错误,并根据错误类型将其重定向到错误页面。

AFAIK Apache无法处理ZF应用程序引发的错误。这是因为所有请求都将发送到index.php。在ZF中定制错误页面并不困难。此外,您还可以轻松地保持标准布局。A将解释如何处理错误以及定制错误页面非常容易。

您试图解决的问题已在ZF的错误控制器中解决

请参阅
Error\u Controller
Error\u Controller::errorAction()
源和相应的视图脚本。您可以使用简单的条件或切换布局轻松添加另一个视图脚本:

$this->getHelper('layout')->setLayout('custom404');

欢迎来到SO-)关于问题提交和格式的简短评论。请注意,当您键入(!)问题时,您可以看到提交后问题实际显示方式的预览。这可能对您有帮助,让您看看。欢迎再次光临!通常,所有请求都使用一组标准的.htaccess规则路由到ZF应用程序。然后错误-包括404、500等-由ErrorController处理。您是说您明确希望在Apache(而不是ZF)级别处理它们吗?我知道ErrorController是处理错误的一个选项。然而,我真的不知道如何使用errorcontroller(如何截获错误并将它们重定向到zend中的错误控制器),因此我认为htaccess可能是一个更容易的选择。格式化方面的出色工作。;-)正如其他人所指出的,我将通过
ErrorController
处理错误。请注意,对于默认的ZF设置,将自动调用
ErrorController
,以处理您引用的错误。所以最低限度的使用不需要额外的东西。调整每种类型错误的处理实际上需要调整控制器和脚本。但这并不难,也不是很有教育意义祝你好运我解决了这个问题。我能让错误控制器工作,谢谢你的帮助