WSOD "The provided host name is not valid for this server" My Drupal 8 site only works with www. but without it I'm getting a WSOD with the "The provided host name is not valid for this server" error.

I've tried to implement the suggestions from this thread:
What does &quot;The provided host name is not valid for this server&quot; mean?

Specifically I tried:

$settings['trusted_host_patterns'] = array(
  '^www\.example\.com$',
  '^example\.com$'
);

$settings['trusted_host_patterns'] = [];

$settings['trusted_host_patterns'] = [ '.*' ];


Still, site will only work with www
You need to add your domains into the array as per your first example. I.e.

    $settings['trusted_host_patterns'] = array(
  '^www\.yourdomain\.co\.uk$',
  '^yourdomain\.co\.uk$',
);


Then clear the caches and the message should go away. It may be that you're missing the comma after your second entry.