\Drupal::request()->getHost() This one doesn't include the URL that begins with https://〜, therefore you may want to write it as follows: $hostname = sprintf('https://%s/', \Drupal::request()->getHost()); Tags All Drupal