How to redirect from Observer in Magento 2?

Magento 2, You can redirect to any custom URL from Observer file. When you have created event observer for any specific event and you want to redirect to any URL in a site, You can redirect from observer simply by calling below code,

Create an observer file under app/code/{Packagename}/{Modulename}/YourEventObserver.php

In the following observer, I am redirecting to the (“customer/account/login”) login page of site,

I am displaying two way to redirect to Custom URL from Observer,

1)

2)

Check for Demo 1,

In above execute() function,
When you need redirect to specific URL, You need to pass your custom URL instead of customer/account/login as the second parameter in redirect() function.