1

I want to "disable" frontend in Magento and use only admin interface. So every non-admin page should be redirect to /admin (/admin/dashboard)

I can't find way to do it.

.

  • that might seem like a stupid question, but why? – Julien Lachal Oct 9 '15 at 12:05
  • To clarify, I am using magento as framework for my custom application that is not an eshop / ecommerce. So i am using only backend and when for whatever reason non-admin url shows up i want to redirect it to admin part. – jedi Oct 9 '15 at 13:26
1

In this case,you need use controller_action_predispatch event on

on this event you need redirection to admin url.

using below code:

       $url=   Mage::helper('adminhtml')->getUrl('adminhtml/index/login');

           Mage::app()->getFrontController()->getResponse()
                      ->setRedirect($url)
                                ->sendResponse();

condition: Current store is admin .Check by code: if Mage::app()->getStore()->isAdmin()

Config.xml code:

<global>
...
  <models>
    <magento85915>
      <class>StackOverflow_Magento85915_Model</class>
    </magento85915>
  </models>
    <events>
    <controller_action_predispatch> <!-- identifier of the event we want to catch -->
        <observers>
          <controller_action_predispatch_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>magento85915/observer</class> <!-- observers class alias -->
            <method>adminRedirection</method>  <!-- observer's method to be called -->
          </controller_action_predispatch_handler>
        </observers>
      </controller_action_predispatch>
    </events>
  </global>

observer code:

<?php
class StackOverflow_Magento85915_Model_Observer
{

          public function adminRedirection(Varien_Event_Observer $observer)
          {
              $controller_action= $observer->getEvent()->getControllerAction();
              $request=$controller_action->getRequest();

              // redirection fire when current store is not aadmin
              if (!Mage::app()->getStore()->isAdmin()):
              // Get admin log page url
               $url=   Mage::helper('adminhtml')->getUrl('adminhtml/index/login');
              /* forcefull redirection  to admin login page */
                   Mage::app()->getFrontController()->getResponse()
                              ->setRedirect($url)
                                        ->sendResponse();
                        exit;
                  endif;
              return true;
        }



}
  • Thank you for your answer. I tried add code directly to Mage_Core_Controller_Varien_Front but it's called even on admin pages and i am getting too many redirects error by browser – jedi Oct 9 '15 at 13:33
  • ok. i will check.. – Amit Bera Oct 9 '15 at 13:35
  • please check.. answered update. – Amit Bera Oct 9 '15 at 14:36
  • Thank you sir, worked like charm ! – jedi Oct 12 '15 at 16:15

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.