Skip to main content
Improves post formatting
Source Link
kenorb
  • 14.3k
  • 10
  • 98
  • 168

Define a controller. And the and redirect to external URL  . Use TrustedRedirectResponse

Use TrustedRedirectResponse class in case you know that you want to redirect to an external URL. Example below:

use Drupal\Core\Controller\ControllerBase; 
use Drupal\Core\Routing\TrustedRedirectResponse; 
class ExampleController extends ControllerBase {
 
   public function example() {
    return new TrustedRedirectResponse('https://google.com');  
  }
 }

Define a controller. And the redirect to external URL  . Use TrustedRedirectResponse class in case you know that you want to redirect to an external URL. Example below:

use Drupal\Core\Controller\ControllerBase; 
use Drupal\Core\Routing\TrustedRedirectResponse; 
class ExampleController extends ControllerBase {
 
   public function example() {
    return new TrustedRedirectResponse('https://google.com');  
 }
 }

Define a controller and redirect to external URL.

Use TrustedRedirectResponse class in case you know that you want to redirect to an external URL. Example below:

use Drupal\Core\Controller\ControllerBase; 
use Drupal\Core\Routing\TrustedRedirectResponse; 
class ExampleController extends ControllerBase {
 
  public function example() {
    return new TrustedRedirectResponse('https://google.com');  
  }
}
Source Link
Shreya Shetty
  • 2.9k
  • 14
  • 28

Define a controller. And the redirect to external URL . Use TrustedRedirectResponse class in case you know that you want to redirect to an external URL. Example below:

use Drupal\Core\Controller\ControllerBase; 
use Drupal\Core\Routing\TrustedRedirectResponse; 
class ExampleController extends ControllerBase {
 
   public function example() {
    return new TrustedRedirectResponse('https://google.com');  
 }
 }