Question

I want to redirect to specific page.

I have created one script for testing but its not working. I am unable to redirect to another website url.

try {
    require_once __DIR__ . '/app/bootstrap.php';

} catch (\Exception $e) {
    echo 'Autoload error: ' . $e->getMessage();
    exit(1);
}

    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $redirect = $objectManager->get('\Magento\Framework\App\Response\Http');
    $redirect->setRedirect('http://google.in/');

Let me know how can i achieve it.

Was it helpful?

Solution

If you want to redirect from root script, you need to use this

try {
    require_once __DIR__ . '/app/bootstrap.php';

} catch (\Exception $e) {
    echo 'Autoload error: ' . $e->getMessage();
    exit(1);
}

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();


$urlInterface = $objectManager->get('Magento\Framework\UrlInterface');
$response = $objectManager->get('\Magento\Framework\App\ResponseInterface');
$response->setRedirect('http://google.in/')->sendResponse();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top