我用开发了一个网站。为了处理错误,我想在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://www.mysite.com/wesgtsgsfd/sgsdf时遇到错误。它可能因维护而关闭或配置不正确。 以下是一些建议:稍后重新加载此网页。HTTP Error 500 (内部服务器错误):当服务器试图满足请求时遇到意外情况。
有没有人想过修复我的htaccess文件,以便Apache能够正确地处理错误并根据错误类型将它们重定向到错误页面。
发布于 2011-07-24 14:31:13
您要解决的问题已经在ZF的错误控制器中解决了。
请参阅Error_Controller
、Error_Controller::errorAction()
源代码和相应的视图脚本。您可以使用简单的条件轻松地添加另一个视图脚本,或者切换布局:
$this->getHelper('layout')->setLayout('custom404');
发布于 2011-07-24 12:29:03
AFAIK Apache无法处理ZF应用程序引发的错误。这是因为所有的请求都要发送到index.php。在ZF中自定义错误页面并不困难。此外,您可以轻松地保持标准布局。快读将解释如何处理错误,并且很容易自定义错误页面。
https://stackoverflow.com/questions/6808888
复制