My event code in config.xml


My Observer.php Code

class Test_Redirect_Model_Observer extends Varien_Event_Observer{

    public function redirect($observer){

        $session = Mage::getSingleton("customer/session");



                $someUrl = "SOME URL";


                $someOtherUrl = "SOME OTHER URL";

        catch(Exception $e) {



Please guide me on why I am stuck in Infinite Loop when redirect from Observer.


  • You are getting the redirect because your code is always called. You need some kind of restriction for when the redirect is not made. Take a look at this: magento.stackexchange.com/a/15890/146. I think it's something similar to what you need.
    – Marius
    Mar 12, 2014 at 9:58
  • I just need to redirect to login page if customer not logged in & redirect to cart page if logged in..How can I achieve this with the above code and what restrictions I need to put for the same ?
    – Mark
    Mar 12, 2014 at 10:08
  • Redirecting a not logged in customer to the login is exactly what the code does in the link I gave you. And if the customer is logged in and you always redirect to the cart how can he perform other actions? Like adding a product to the cart.
    – Marius
    Mar 12, 2014 at 11:01
  • @Marius I agree with you. I was just testing out the code and thanks for the link.
    – Mark
    Mar 12, 2014 at 11:31

1 Answer 1


I suggest you override AccountController.php's _loginPostRedirect() near

if ($session->isLoggedIn()) {
            if (!Mage::getStoreConfigFlag(
            )) {
                $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
                if ($referer) {
                    // Rebuild referer URL to handle the case when SID was changed
                    $referer = Mage::getModel('core/url')
                    if ($this->_isUrlInternal($referer)) {
            } else if ($session->getAfterAuthUrl()) {
        } else {
  • 1
    The _loginPostRedirect() will only be called when I explicitly login. I need to redirect user to login page is not logged in and redirect to cart page if logged in.
    – Mark
    Mar 12, 2014 at 10:48

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