Zend: 500 error instead of 404

285 views Asked by At

Problem with 404 errors in Zend Framework 1. http://www.url.nl/path/wrong returns a 404 error (because the /path part exists). But when the first path is wrong (the root), it returns a 500 error. So http://url.nl/wrong returns a 500. Anybody who experienced the same issue? This is my 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 '.$role;

                if (!$role) $this->_helper->layout->setLayout ( 'pages/404' );
                else $this->_helper->layout->setLayout ( '404' );

                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = 'Application error';
                break;
        }

        if ($errors->exception instanceof Zend_Acl_Exception) {
            // send needed headers...
            // prepare log message...
            // render info: resource_not_found.phtml


            $this->_helper->viewRenderer('error-no-access');
            $this->_helper->layout->setLayout ( '403' );            
        }

EDIT: The ACL manager was the problem, contained some problems in redirects etc. Most of the pages where redirected to the back-end and restricted because a normal user was trying to reach the page.

1

There are 1 answers

1
Deepak saini On
/*if (!$role) $this->_helper->layout->setLayout ( 'pages/404' );
                    else $this->_helper->layout->setLayout ( '404' );

                    break;
                default:
                    // application error
                    $this->getResponse()->setHttpResponseCode(500);
                    $this->view->message = 'Application error';
                    break;*/

Try commenting the above section (like I did). This will tell you the actual problem at your file location(at your url). Once you know the problem, you can solve it as well.

Hope it helps.