Magento 1.9 – How to Redirect to Controller Action from phtml

magento-1.9redirect

I have one phtml.

In there i m check one variable if that variable is null than it should be redirect to Controller action

I m trying this code:

Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl().'marketplace/vendor/selectcategory'); 

but using this code if variable is not null than also redirect but i don't want this. I need to redirect when variable is null

Best Answer

Please try this...

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl().'marketplace/vendor/selectcategory');

exit()

better way to use JavaScript:

<script type="text/javascript">location.href = '<?php echo Mage::getBaseUrl().'marketplace/vendor/selectcategory';  ?>';</script>