6

Is there a way to disable an admin route, well actually any route. The use case is I have an extension that comes with a frontend section and an admin section but I do not want the admin section to be used. I have disabled the admin menu items but I would like to disable the route as well so that if there are any other links or someone has it bookmarked they get a 404 or redirected to the dashboard.

I know I could setup different roles and disable for some roles but I want it to be a complete removal.

3 Answers 3

7

I don't think there is a way to do this without removing the routers tag from the config.xml or adding some observers on the predispatch event that will redirect you to a 404 page.
But I may be wrong. In case I'm wrong here is a place to start.
The routers section of the config.xml files is parsed in Mage_Core_Controller_Varien_Router_Standard::collectRoutes.
From what I saw in there, there is no check for a disabled flag or something like that.
There might be a chance if the the module does not use the admin path for backend pages.
So if the router is not declared like this:

    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Module_Name before="Mage_Adminhtml">Module_Name_Adminhtml</Module_Name>
                </modules>
            </args>
        </adminhtml>
    </routers>

but uses the other way of declaring routers:

    <routers>
        <module_name>
            <use>admin</use>
            <args>
                <module>Module_Name</module>
                <frontName>route_name</frontName>
            </args>
        </module_name>
    </routers>

You can create a module and just change the <use> tag value to something that's not admin or standard.

So your new module that depends on the original one can have the routers section like this:

<routers>
    <module_name>
        <use>go-away</use>
    </module_name>
</routers>

Why I thing it could work? because in the method mentioned above the only if with no else that could return false is if ($use == $useRouterName).
This is just an assumption. I haven't tested it. I don't have any extensions that use this type of routers for backend.

4
  • Not a bad idea, with the use then you end up on a front-end 404 page, but that is not so bad in this case. Commented Sep 25, 2014 at 14:03
  • @DavidManners. Just curious, how did you did it?
    – Marius
    Commented Sep 30, 2014 at 7:57
  • I did it with <use>we-do-not-want-this-module</use> it gives you a front end 404 page but that is completely fine for me. Open to other ideas though. Commented Sep 30, 2014 at 7:58
  • Nice! That's how I disabled the product review functionality and it works well
    – Erfan
    Commented Oct 15, 2015 at 3:57
1

I would probably just do something like rewrite the relevant controller action and then just have a redirect to dashboard or some other page.

2
  • yeah I was thinking about this but some modules can have a lot of actions, I was also thinking about simply changing the frontName to so random string Commented Sep 25, 2014 at 13:53
  • Sure ok, how about a <from> <to> config.xml rewrite then. As it's under <global> it should work for admin as well? Commented Sep 25, 2014 at 13:57
1

Why can't you use preDispatch to do this job for you. Try this code inside your modules's admin controller

public function preDispatch()
{
    parent::preDispatch();
    //Mage::getSingleton('adminhtml/session')->addError(
       // Mage::helper('cms')->__('Requested URL is not allowed'));
    $this->getResponse()->setRedirect(Mage::helper("adminhtml")->getUrl("adminhtml/dashboard/index"));

}

I have tried this in CMS > Pages controller and it works just fine. I tried to add an error message, but it didn't work. I think you will be able to resolve it. If you find, why the error message didn't work, inform me too :-)

3
  • My idea was to not use code but to simply turn the router off like you can with other items like the menu or observers. With your answer I would have to write a bit of config and a controller, though it would be small, as I do not want to directly edit the modules code. Not saying it is wrong just noting my thinking. Commented Sep 25, 2014 at 15:19
  • so you dont have controller for your extension? I was not aware of it. anyway I am leaving this answer here. It may help future visitors :) Commented Sep 25, 2014 at 15:24
  • it was more about disabling another extensions controller. sure I can write mine that extends it no problem. Just wanted some ideas about different ways Commented Sep 25, 2014 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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