2

I am trying to add the Trusted Host setting. I copied the code directly from the settings.php file, making sure I removed the * and changed the example to my domain. Using the first example

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

The site would not load....got an error stating domain was disallowed

Today using this code and

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

I am getting an unexpected error and the site won't load

This is a new site on a shared host. It can't be this difficult! I must be missing something!

4
  • Hey we have code highlighting here. Please use this, it's hard to tell what really is in your settings file. Then read this, they have plenty of examples there: drupal.org/forum/support/post-installation/2016-06-30/…
    – leymannx
    May 14, 2018 at 21:32
  • Yes - I read that post. I copied the example and pasted it into my settings.php file after making the necessary changes and upon loading the site I get "The website encountered an unexpected error. Please try again later."
    – Shadow
    May 14, 2018 at 22:55
  • Then the pattern isn't matching. What's the URL you wanna trust and how does your pattern look?
    – leymannx
    May 15, 2018 at 5:33
  • 1
    You need to check your logs to find the real error message, it’s random guesswork without that
    – Clive
    May 15, 2018 at 7:31

3 Answers 3

2

I don't know if I was introducing a problem by editing the settings.php off line and then uploading it but decided to edit it with the editor in the file manager on cpanel. I first changed the permissions on the default folder to 755 and opened the folder. Then I highlighted the settings file and changed the permissions to 755. Then I clicked the edit button and located the Trusted Host settings and copied the code. I then pasted it AT THE END of the settings.php file and made the necessary changes to reflect my domain and saved the file and closed the setting file. In a different window, I had the website status page loaded and just refreshed it. IT worked! I don't know why doing it this way worked (editing the file on the server vs offline and uploading it.) but it did! Then I just change the file permissions back to what they were .

0

Be sure that the uncommented lines are NOT within the original comments. For example, the following will NOT work, even though they have been "uncommented", because they are still within the opening /** and closing */ comments

/**
 * Trusted host configuration.
 *
 * For example:
 * @code
 * $settings['trusted_host_patterns'] = array(
 *   '^www\.example\.com$',
 * );
 $settings['trusted_host_patterns'] = array(
   '^www\.realsitename\.com$',
 );
 * @endcode
 * will allow the site to only run from www.example.com. *
 * 
 */

Adding it after the closing */ (or at the very end, but that makes it hard to find) will work:

/**
 * Trusted host configuration.
 * (snipped)
 */
 $settings['trusted_host_patterns'] = array(
   '^www\.realsitename\.com$',
 );
0

Use the following code at the end of sites/defaut/settings.php file

/**
 * Trusted host configuration.
 * (snipped)
 */
 $settings['trusted_host_patterns'] = [
 '^localhost$',
 '^127\.0\.0\.1$',
 ];

You need to look at this link also For a status check reports

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.