Trying to programmatically redirect
See drupal_goto() has been removed.


  Drupal 8 (procedural)

use Symfony\Component\HttpFoundation\RedirectResponse;

function my_menu_callback_foo() {
  //....
  return new RedirectResponse(\Drupal::url('user.page'));
}

  
  Drupal 8 (properly injected)

use Drupal\Core\Controller\ControllerBase;

class MyControllerClass extends ControllerBase {

  public function foo() {
    //...
    return $this-&gt;redirect('user.page');
  }
}

  
  If the route name is not known use RedirectResponse with a URL. When redirecting to an external location, use TrustedRedirectResponse.

use Drupal\Core\Controller\ControllerBase;

class MyControllerClass extends ControllerBase {

  public function foo() {
    //...
    return new TrustedRedirectResponse('https://example.com/some/path'); // for eg. Url::fromUserInput(\Drupal::destination()-&gt;get())-&gt;setAbsolute()-&gt;toString();
  }
}