Does anybody know of a comprehensive list of Magento Core's routes? I'm sure I could create a pretty accurate list by parsing the controller files for Action methods, I'm just wondering if anybody knows of a list that has already been compiled, or a tool for doing so (a tool would be nice as I could potentially use it against community modules).

On a related note, is there any simple way to issue 404's for core routes that you don't wish to function? For example, if I wish to disable the ability to use the catalogsearch/advanced is there any simple way of doing so?

Some options spring to mind, but I'm not sure if any of them are ideal:

  1. I could create my own CatalogSearch_Advanced controller that overrides the action(s) and throws a 404. This would work OK, but depending on which actions I wished to disable could require multiple overloads.
  2. I could create my own Router that just matches the values I don't want and throws the 404. I'm not familiar enough with the Magento Routers to know for sure, but I assume I can get this to load early enough in the Router stack.

Am I missing something?


You can get the list of routes from the config like this:

Mage::getConfig()->getNode('frontend/routers'); //for frontend
Mage::getConfig()->getNode('admin/routers');//for admin

These will return an instance of Mage_Core_Model_Config_Element where the keys of all the child elements will be the first element in the route. So if the url looks like this 'module/controller/action' you will see in the list of keys 'module'.
I don't know if there is a way to get all the possible urls, because controllers might be overwritten and any method inside a controller that ends in Action can be an action. (Maybe you can get them using Reflection.
As for redirecting some action to 404, you can do it with observers.
Create an observer for the predispatch of your action. For example for catalogsearch_advanced the event is controller_action_predispatch_catalogsearch_advanced_index.
In your observer create a method called show404 that looks like this:

public function show404($observer){
    $controller = $observer->getEvent()->getControllerAction();
    $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
    $controller->getResponse()->setRedirect(Mage::getUrl('noroute'), 404);

So your event should look like this:

    <events><!--event tag-->
        <controller_action_predispatch_catalogsearch_advanced_index><!--event name-->
                <redirects><!-- unique identifier -->
                    <class>module/observer</class><!-- observer identifier -->
                    <method>show404</method><!-- method name -->

For each page you want to redirect to not found you can add one of these events. you can use the same observer and method for all redirects.
For additional info, you can find here a nice article about magento routers wrote by Alan Storm

|improve this answer|||||
  • This way of fetching routes is extemely helpful for debugging 404s. – Darth Egregious Mar 20 '14 at 15:32
  • I was trying to use it: public function CmsPageRender($observer) { $websiteId = Mage::app()->getStore()->getWebsiteId(); if ($websiteId != 1) { $controller = $observer->getEvent()->getControllerAction(); $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); $controller->getResponse()->setRedirect(Mage::getUrl('noroute'), 404); return false; }$cms_page = $observer->getEvent()->getPage(); Mage::helper('youngdogs_cms')->parsePage($cms_page); return $this; } , this observer check if its ON for the store.whats wrong? – ntzz Sep 3 '15 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.