【发布时间】:2015-08-01 19:09:20
【问题描述】:
我在 Zend Framework 1 项目中的 404 页面有问题。
如果出现路由、操作或控制器错误,我的应用程序会返回 404 错误。唯一的问题是我希望我的链接更改为 www.exemple.com/error404.html 之类的内容。所以假设我有这个链接:
我的应用程序返回 404 错误,但链接保持不变。我希望我的链接从上面重定向到:
在我的 ErrorController 中,我有以下代码:
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
break;
}
$this->view->exception = $errors->exception;
$this->view->request = $errors->request;
}
我尝试重定向到我创建的页面,但重定向代码是 302,我需要 404。
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
//redirect to a 404 page
$this->_redirect('/error404');
break;
}
$this->view->exception = $errors->exception;
$this->view->request = $errors->request;
}
谢谢!
【问题讨论】:
标签: redirect zend-framework routes http-status-code-404