Magento 2 – How to Redirect from PHTML File

magento-1.7magento-1.9magento2PHPredirect

I want to redirect the user to specific page in Magento 2 from PHTML file.

In Magento 1 we use following method to redirect

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl().'?login=false');`

but not finding any solution for Magento 2.

I have also read this blog but it shows to create a custom module for that.
As I don't want to do this from the module.

Please provide any solution if available.

Edit

I just want to redirect the user to the specific page if not log in for that to create module it will be a not a good thing.

Best Answer

Add this code in your phtml file....

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$redirect = $objectManager->get('\Magento\Framework\App\Response\Http');
$redirect->setRedirect('Your path....');
Related Topic