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');
}
}