Redirect 将404错误重定向到自定义404页面

Redirect 将404错误重定向到自定义404页面,redirect,zend-framework,routes,http-status-code-404,Redirect,Zend Framework,Routes,Http Status Code 404,我在Zend Framework 1项目中的404页面有问题 在路由、操作或控制器错误的情况下,我的应用程序返回404错误。唯一的问题是,我希望我的链接在类似www.example.com/error404.html的内容中更改。假设我有这个链接: 我的应用程序返回404错误,但链接保持不变。我希望我的链接从上面重定向到: 在我的ErrorController中,我有以下代码: public function errorAction() { $errors = $this->_

我在Zend Framework 1项目中的404页面有问题

在路由、操作或控制器错误的情况下,我的应用程序返回404错误。唯一的问题是,我希望我的链接在类似www.example.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;
}

谢谢大家!

404也不能是重定向,两者是互斥的。如果您只想呈现
error404
模板,请从错误控制器执行此操作(或修改现有的错误操作模板)


另请参见谷歌关于404软件的建议:

事实上,我已经更改了404页面模板内容,我的问题是我需要的链接类似于www.example.com/404.html。谢谢