开发者

Zend Framework with htaccess

I developed a website using Zend Framework. In order to handle errors, I want to add to the htaccess file the following lines so I can redirect the user to the corresponding every time there is an error.

ErrorDocument 500 /errors/500.html
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html

so my htaccess file now in the /public folder looks like this:

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

However it seems not to work and it doesn't redirect me to any of these pages and instead it displays this classic error page.

Server error

The website encountered an error while retrieving http://www.mysite.com/wesgtsgsfd/sgsdf. It may be down for maintenance or configured incorrectly.

Here are some suggestions: Reload this web page later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the serve开发者_高级运维r was attempting to fulfil the request.

Does anybody have an idea about to fix my htaccess file so Apache can handle the errors properly and redirect them to the error page according to the error type.


The problem you are trying to solve is already solved in ZF's Error Controller.

See the Error_Controller, Error_Controller::errorAction() sources and the corresponding view scripts. You may easily add another view scripts using simple conditions there or switching the layout:

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


AFAIK Apache can't handle errors thrown by your ZF app. This is because all requests are going to the index.php. its not difficult to customise the error pages in ZF. Plus you can keep the standard layout with ease. A quick read will explain how errors are handled and its quite easy to customise the error page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜