Question

I've faced the problem: my seo-specialist asked me to redirect all 404 to same url (/404.html). Not to show content on noRoute page but redirect to this url.

I've made changes in /app/code/core/Mage/Cms/controllers/IndexController.php:

/**
 * Render CMS 404 Not found page
 *
 * @param string $coreRoute
 */
public function noRouteAction($coreRoute = null)
{
    $this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
    $this->getResponse()->setHeader('Status','404 File not found');

    $pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE);
    if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
        $this->_forward('defaultNoRoute');
    }
    $this->_redirect($pageId);
}

It works on local version but doesn't on live.

When I comment headers it works:

// $this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
// $this->getResponse()->setHeader('Status','404 File not found');

But I think it's incorrect solution, please help me.

Was it helpful?

Solution

Rather then changing core module I would suggest you to look into

System > Configuration > Web > Default Pages > Default No-route URL

Here you can see that default no-route URL is cms/index/noRoute. So just change this from your module controller and do your changes. For example (YOUR_ROUTE/CONTROLLER NAME/ACTION NAME)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top