You are here

Drupal 8: Trusted Hosts in settings.php

I found Drupal's instructions for setting trusted hosts to be obtuse, confusing and nearly incomprehensible. After trial and error I have found the syntax that works. Following is the code -- and, most importantly, the location in settings.php near the top of the file to place the code -- for trusted host settings. Replace "example" with your domain name. (Remember, to edit settings you need to change permissions. Always re-set permissions to 0404 when finished editing.)

When you are finished editing, navigate to admin/reports/status#checked and you should see the following down near the lower half of the table:

The trusted_host_patterns setting is set to allow ^example\.com$, ^.+\.example\.com$

Begin code placement in settings.php:

* In addition to customizing application settings through variables in
* settings.php, you can create a services.yml file in the same directory to
* register custom, site-specific service definitions and/or swap out default
* implementations with custom ones.

$settings['trusted_host_patterns'] = array(

* Database settings:

End code placement in settings.php.