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.

2
  • is this code in your root and you want to redirect from root script? Commented Apr 10, 2018 at 16:02
  • yes, this code is in root script and i want to do redirect to another url. Commented Apr 10, 2018 at 16:02

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.