Redirect a form to an external URL Want to redirect $form_state to external URL after successful registration of the user. Like, need to redirect to facebook after user registration.

  $query = "http://facebook.com";
  $url = Url::fromRoute('user.register', [], ['query' =&gt; ['service' =&gt; $query]]);
  $form_state-&gt;setRedirectUrl($url); 
  //$url = Url::fromUri($query); 
  return RedirectResponse::create($url-&gt;toString(), 302); 

  $form_state&gt;setResponse(newTrustedRedirectResponse('https://google.com', 302)); 
  return new RedirectResponse($query); 
  $form_state-&gt;setRedirect($query); 
  $form_state-&gt;setRedirectUrl(Url::fromUri($query));
  $response = new RedirectResponse($query); 
  $response-&gt;send();


tried above all methods, but nothing works.
The method that you missed is $form_state-&gt;setResponse(). In combination with a TrustedRedirectResponse object, which exists for security reasons (to prevent users from accidentally being redirected to another site), you can use code similar to the following.

$response = new TrustedRedirectResponse('https://facebook.com');
$form_state-&gt;setResponse($response);