Redirect to previous page in Magento after logout

By default Magento sends a user to a logoutSuccess page after they choose to log out. This is ‘hard-baked’ into the Customer controller’s logout action in the line $this->_redirect('*/*/logoutSuccess');. You can choose to set the Javascript redirect in the template customer/logout.phtml, but a better idea is to bypass the logout success page entirely.

The way to do this is to override the logoutAction() method in the customerController:

  1. Rewrite the customer controller as documented here
  2. Override the logoutAction() method
  3. Set the redirect as below
    require_once 'Mage/Customer/controllers/AccountController.php';

    class EdmondsCommerce_LogoutRedirect_AccountController extends Mage_Customer_AccountController {
        public function logoutAction()
            $url = Mage::getSingleton('core/session')->getLastUrl();

Tags: magentologoutredirect