How to redirect from observer to external url in magento2..?

magento23
(Arshad Syed) #1

I want a redirect function where It will redirect to external Url from Magento 2 Observer class.

In other CMS like Wordpress, we have wp_redirect(); it will redirect to any URL inside Wordpress or to any External URL.
I am looking a similar kind of function in Magento2.

below I found a link It also not very helpful,

0 Likes

(Varun Jyothi) #2

You can redirect to external URl by using Magento’s “resultRedirectFactory” class like

$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setUrl(‘https://www.google.co.uk’);
return $resultRedirect;

0 Likes

(Arshad Syed) #3

Thanks Varun, About code works fine in Controller class. But I want in Observer class

0 Likes