I discovered an issue with Magento routing logic and I would like to see if anyone can confirm this.
Magento stacks routers admin, standard, then default and processes them one at a time. Magento gets the current module name based on the URL (see Mage_Core_Controller_Varien_Router_Standard::match())
, then checks if the module should be handled by this router, based on a match to a frontName in the Magento config. If a match is found, it routes it. If not, it continues to the next router.
Config excerpt:
<admin> <routers> <myroute> <use>admin</use> <args> <module>MyNamespace_MyModule</module> <frontName>myroute</frontName> </args> </myroute> </routers> </admin> <frontend> <routers> <myroute> <use>admin</use> <args> <module>MyNamespace_MyModule</module> <frontName>myroute</frontName> </args> </myroute> </routers> </frontend>
This means that if you use the same name for your frontend router as your admin router, the admin router will always be matched first, even on frontend pages. Your frontend page will now route as is if were an admin page, using the admin base_url
, which may be different from your store's URL causing a broken redirect.
Note that this issue is not apparent in Magento instances where the admin base URL is the same as the frontend base URL.
Can anyone confirm that my assesment of the router logic is correct here?
Best Answer
You may want to look over Varien/Router/Standard.php as well in particular:
And this is called within the method
match(Zend_Controller_Request_Http $request)
as well ascollectRoutes($configArea, $useRouterName)
as$useRouterName
will sometimes returnadmin
and will also returnstandard
for frontend requests. The assumption sounds correct as it all depends on how magento builds and stacks the_routes
and_modules
private array in this same class:Mage_Core_Controller_Varien_Router_Standard
.I believe in this case you would want to specify the
<use>
node asstandard
for frontend andadmin
for admin, or rewrite the controller action in the<global>
node.I think your best bet is to read over:
and/or step through the logic with X-debug.
Even Alan Storm in his article writes how the same routers used for frontend and backend shouldn't be the same.