How to configure Trusted_Host_Settings for subdomains?

The documentation does not give an example of a subdomain.

For example, I have an Add-On domain that points to, but the subdomain is

  • Did not work. Invalid hostname for this computer. Perhaps using the term subdomain caused confusion. The pattern I have to match is: Sites in folders under the main domain. – David Apr 28 at 17:58

It's actually documented in settings.php file as in examples:

Drupal 8.5.x

$settings['trusted_host_patterns'] = array(
  '^example\.com$',           // Matches naked domain only.
  '^.+\.example\.com$',       // Matches any subdomains.
  '^subdomain\.example\.com', // Matches a specific subdomain.

You can easily define any naked or sub-domain, as long as defined regex pattern matches them correctly.

  • Good catch The other things I have seen did not provide a pattern like this. Thanks. – David Apr 27 at 21:43
  • Did not work. Matching the folder structure of sites under the main site. – David Apr 28 at 18:01
  • You really should read the documentation for the trusted_host_patterns setting. As the name suggests, it's for setting up trusted hostnames. If you don't know the difference between host and path, I also recommend reading up What is a URL? at MDN. – osman Apr 28 at 18:38

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.