I've set no on system configuration-> customer login configuration. But nothing's happen, it still direct to my account dashboard.

How to redirect to previous page after login?

  • Have you this setting on website level and store level ?? Commented Mar 29, 2017 at 6:49
  • on my website level, because there's no option to do that on my store level. @MurtuzaZabuawala Commented Mar 29, 2017 at 6:52
  • So You have done this changes in both website level and global level ?? Commented Mar 29, 2017 at 6:54
  • yes, I have done. But after i logged in, it still direct to account dashboard page Commented Mar 29, 2017 at 7:01

4 Answers 4


You have to rewrite in local loginPostAction() from app/code/core/Mage/Customer/controllers/AccountController.php to app/code/local/Customer/controllers/AccountController.php Then you put this :

 public function loginPostAction(){

    if (!$this->_validateFormKey()) {

    if ($this->_getSession()->isLoggedIn()) {
    $session = $this->_getSession();

    if ($this->getRequest()->isPost()) {
        $login = $this->getRequest()->getPost('login');
        if (!empty($login['username']) && !empty($login['password'])) {
            try {
                $session->login($login['username'], $login['password']);
                if ($session->getCustomer()->getIsJustConfirmed()) {
                    $this->_welcomeCustomer($session->getCustomer(), true);
            } catch (Mage_Core_Exception $e) {
                switch ($e->getCode()) {
                    case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                        $value = $this->_getHelper('customer')->getEmailConfirmationUrl($login['username']);
                        $message = $this->_getHelper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
                    case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                        $message = $e->getMessage();
                        $message = $e->getMessage();
            } catch (Exception $e) {
                // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
        } else {
            $session->addError($this->__('Login and password are required.'));

    // The adding code here
    $this->_redirectReferer(); //redirect you to the previous page
    $this->_redirect('/'); // redirect you to the home page
    $this->_redirect('wishlist'); //redirect you to wishlist page for exemple
  • I don't know why when I set "no" my login page is not give an alert when I insert wrong password Commented Mar 31, 2017 at 8:50
  • Either the problem comes from the theme, or you have removed the block that displays the messages$this->getMessagesBlock()->getGroupedHtml(); or the controller if you had modified it, please compare with my controller.
    – PЯINCƎ
    Commented Mar 31, 2017 at 9:39

You can customer_login observer. After customer has logged in, you can redirect the customer where you want.

Here is how to create observer for customer login How to bind an action after customer login success using Magento?


Set NO on System > Configuration > Customers > Customer Configuration > Login Options

Then in your login.phtml files (both, persistent/customer/form and customer/form on your template folder), change the action of your <form> to:

action="<?php echo str_replace('login', 'loginPost', $this->helper('customer')->getLoginUrl()) ?>"

But remember, DO NOT EDIT THE CORE! Create a custom extension to accomplish this job.

Reference: https://stackoverflow.com/a/16099279/5810265

  • I don't know why when I set "no" my login page is not give an alert when I insert wrong password Commented Mar 31, 2017 at 8:49
  • @syahidahhumairoh I think you will have a problem with core files! Commented Mar 31, 2017 at 9:29

Please use below code to back to prev page after login

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$url = $objectManager->create('\Magento\Framework\UrlInterface');
$loginUrl = $url->getUrl('customer/account/login', array('referer' => base64_encode($url->getCurrentUrl())));
<a href="<?php echo $loginUrl;?>">Login</a>
  • OP has asked for M1, not M2 :) but nice to know for m2...
    – JJ15
    Commented May 8, 2018 at 11:57
  • Dont use object manager even in M2
    – Sandipan S
    Commented Jun 7, 2018 at 9:43

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.