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 at 17:58

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

Drupal 8.5.x
https://cgit.drupalcode.org/drupal/tree/sites/default/default.settings.php?h=8.5.x#n712

<?php
$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. domain.com/subdomain.info 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

 
discard

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.