I am in catalog\product\compare\list.phtml and I want to redirect to the homepage, like this:

if($someThing) {
    // redirect to homepage
    $this->_redirect('home'); // --> doesnt work
    $this->_redirect(Mage::getBaseUrl()); // --> doesnt work

I tried several things, none worked so far. How do I do it right?


  • 2
    try $this->_redirect('/');
    – Keyul Shah
    May 14, 2014 at 8:35
  • keyul It Worked for me thanx a lot Apr 7, 2016 at 13:36

3 Answers 3


From a template you can simply use the following:


I am interested as to why you are doing redirects directly in the template rather than at the controller level?

  • Agree. JavaScript might be another option, closer to a "view" solution. Still you might want to move this to a controller.
    – mbalparda
    Jul 15, 2014 at 23:07

As _redirect() is a controller class function .By using this you cannot direction at any pages from phtml page. So you need to controller object which will redirect to home page


exit stop execution of current page


You should never redirect to the homepage from a template.
Do that from the controller before any output is done.
You can use the code that DavidManners gave you, but do it before you call renderLayout in the controller.

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.