Skip to main content

You can get the hostname, "drupal8.local", directly from the getHost() request:

$host = \Drupal::request()->getHost(); 

In some cases you might want to get the schema as well, fx https://drupal8.local:

$host = \Drupal::request()->getSchemeAndHttpHost(); 

You can get the hostname, "drupal8.local", directly from the getHost() request:

$host = \Drupal::request()->getHost(); 

You can get the hostname, "drupal8.local", directly from the getHost() request:

$host = \Drupal::request()->getHost(); 

In some cases you might want to get the schema as well, fx https://drupal8.local:

$host = \Drupal::request()->getSchemeAndHttpHost(); 

You can get the hostname, "drupal8.local", directly from the getHost() request:

$host = \Drupal::request()->getHost(); 

You can get the hostname directly from the request:

$host = \Drupal::request()->getHost(); 

You can get the hostname, "drupal8.local", directly from the getHost() request:

$host = \Drupal::request()->getHost(); 
Source Link
Clive
  • 168.4k
  • 19
  • 305
  • 338

You can get the hostname directly from the request:

$host = \Drupal::request()->getHost();