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 website.info, but the subdomain is mainsite.com/website.info

  • Did not work. Invalid hostname for this computer. Perhaps using the term subdomain caused confusion. The pattern I have to match is: domain.com/subdomain.info Sites in folders under the main domain. – David Apr 28 '18 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.

|improve this answer|||||
  • Good catch The other things I have seen did not provide a pattern like this. Thanks. – David Apr 27 '18 at 21:43
  • Did not work. domain.com/subdomain.info Matching the folder structure of sites under the main site. – David Apr 28 '18 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 '18 at 18:38

Your Answer

