0

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.

  • is this code in your root and you want to redirect from root script? – Prashant Valanda Apr 10 '18 at 16:02
  • yes, this code is in root script and i want to do redirect to another url. – Sanjay Jethva Apr 10 '18 at 16:02
2

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();

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.