How to get the base URL of a site My site is on http://drupal8.local/. How do I get the drupal8.local part of that URL?

Url::fromRoute('&lt;'current'&gt;') or base_path() returns the path parth of the URL; For example, for http://drupal8.local/a/b/c/d/e/f, they return '/a/b/c/d/e/f' when I just need to get 'drupal8.local'. 

How can I get that part of the URL?
You can get the hostname, "drupal8.local", directly from the getHost() request:

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


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

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