Magento – Overload noRouteAction for 404 Errors not working

404-pagecontrollersmagento-1.8module

I want to overload the noRouteAction() to search for products based on the url and if found, redirect there.
Else I want to use the default 404 page.
Here is what I have: (for magento 1.8)

app/etc/modules/ACME_ErrorHandler.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <ACME_ErrorHandler>
            <active>true</active>
            <codePool>local</codePool>
        </ACME_ErrorHandler>
    </modules>
</config>

app/code/local/ACME/ErrorHandler/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ACME_ErrorHandler>
            <version>1.0.2</version>
            <depends>
                <Mage_Page />
            </depends>
        </ACME_ErrorHandler>
    </modules>

    <frontend>
        <routers>
            <SkuRoute>
                <use>standard</use>
                <args>
                    <module>ACME_ErrorHandler</module>
                    <frontName>ErrorHandler</frontName>
                </args>
            </SkuRoute>
        </routers>
    </frontend>

    <global>
        <routers>
            <cms>
                <rewrite>
                    <index>
                        <to>ACME_ErrorHandler/index</to>
                        <override_actions>true</override_actions>
                        <actions>
                            <noroute><to>ACME_ErrorHandler/index/noroute</to></noroute>
                        </actions>
                    </index>
                </rewrite>
            </cms>
        </routers>
    </global>


</config>

app/code/local/ACME/ErrorHandler/controllers/IndexController.php

<?php
class WellLinked_ErrorHandler_IndexController extends Mage_Cms_IndexController
{
    public function noRouteAction($coreRoute = null)
    {
        header("X-Custom-Mod: working");
        parent::noRouteAction($coreRoute);

    }
}

The Problem is, it doesn't work!
When the Module is activated, every nonexisting URL gives this error:

a:5:{i:0;s:52:"Front controller reached 100 router match iterations";i:1;s:377:"#0 /var/www/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(179): Mage::throwException('Front controlle...')
#1 /var/www/magento/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#2 /var/www/magento/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#3 /var/www/magento/index.php(126): Mage::run('default', 'store')
#4 {main}";s:3:"url";s:38:"/no-such-url";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}

What did I do wrong?

Best Answer

You can use the default no route URL instead rewriting; Set the URL of your new controller Action in : System -> Configuration -> General -> Web -> Default Pages -> CMS No Route page

Hope that can help.