Drupal - Error message - host name is not valid for this server

By xngo on January 23, 2020

In Drupal 8, I got the following error message when I install the backup of the live website on my local development machine.

The provided host name is not valid for this server.

Solution

The cause of this issue is I enabled Trusted Host settings on the live website. Now that I brink it back to my local development environment, it doesn't recognized the domain that I set earlier.

To resolve this issue, I edit the .../sites/default/settings.php and add '^localhost$', to the $settings['trusted_host_patterns'] variable as follows:

$settings['trusted_host_patterns'] = array(
  '^localhost$',
  '^example\.com$',
  '^.+\.example\.com$',
  '^.+\.jsdelivr\.net$',
  '^.+\.cloudflare\.com$',
);

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.