Magento – Call to a member function rewrite() on a non-object in app/code/core/Mage/Core/Controller/Varien/Front.php on line 165

controllersfatal errormagento-1.7

My site is not loading, as I get this error message when type in the URL:

Fatal error: Call to a member function rewrite() on a non-object in app/code/core/Mage/Core/Controller/Varien/Front.php on line 165

Does any one familiar with what could be wrong here?

Best Answer

If you look at the file to which magento points out, you can find the below line which comes inside dispatch method

File : app/code/core/Mage/Core/Controller/Varien/Front.php

$this->_getRequestRewriteController()->rewrite();

The error says rewrite() is calling on a non-object. This means that, $this->_getRequestRewriteController() provides you a non-object (most probably it returns an empty value).

Why $this->_getRequestRewriteController() gives you a non-object ? In order to find the reason, let us have a look on this method definition.

protected function _getRequestRewriteController()
{
    $className = (string)Mage::getConfig()->getNode('global/request_rewrite/model');

    return Mage::getSingleton('core/factory')->getModel($className, array(
        'routers' => $this->getRouters(),
    ));
}

The method just trying to create a model instance of $className. Here $className holds a value which is returned by $className = (string)Mage::getConfig()->getNode('global/request_rewrite/model');. The default value which return by this call is core/url_rewrite_request. This means the method _getRequestRewriteController() is supposed to return an instance of model class Mage_Core_Model_Url_Rewrite_Request by defalt.

Based on this analysis, the error may be caused due to

  1. You may have a wrong class name in the above specified node. app/code/core/Mage/Core/etc/config.xml is used to define this node value. Since it is a core file, alternation happens here may be a rare chance. There is a possibility of rewriting this node by any external plugins. So this should be validated first.

  2. Ultimately your magento application do not have the file which defines this class Mage_Core_Model_Url_Rewrite_Request which normally appers at app/code/core/Mage/Core/Model/Url/Rewrite/Request.php

  3. I have found out some threads, which gives a hint that permission problems on var/cache directory may also cause this weird issue.

Hope that helps.