9

In my admin controller action I want to redirect to the previous page. How can I do this?

2 Answers 2

27

Try this:

$this->_redirectReferer();

it does a little more than redirect to the previous page. If you specify in the url a parameter uenc it will consider that as the referrer.

1
  • Thanks it worked properly as I expected. And I went through the function where located in Mage_Core_Controller_Varien_Action. I think Mahmood Rehman's answer contains the development which has been done through this _redirectReferer() function.
    – Sukeshini
    Commented Nov 1, 2013 at 10:01
9

Try this code :

 Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);
        Mage::app()->getResponse()->sendResponse();
            exit;
1
  • This worked perfectly. Thanks a lot. When you go through the Mage_Core_Controller_Varien_Action class you can find the _redirectReferer() function which has developed similar way as your answer. Thanks and +1
    – Sukeshini
    Commented Nov 1, 2013 at 10:05

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.