How To Configure Trusted Host settings for Drupal 8 Website

| Drupal Development | 58 seen

In today's Drupal tutorial series I will talk about Trusted host settings, what they are and how to configure them.

In short, Trusted host settings protects against HTTP HOST Header attacks (prevent your site from thinking it is someone else).

Drupal 7 added a new feature into the core that is not user-facing directly but is sometimes called poor man's cron. The feature triggers the periodic tasks of a Drupal site like emptying log files, sending e-mails, and clearing out caches. This feature, when combined with dynamic detection of the "base url" (added in Drupal 4.7), can lead to some screwy situations.

Let's start with the oblivious, first noticed a warning in a Drupal 8 website, saying:

The trusted_host_patterns setting is not configured in settings.php. This can lead to security vulnerabilities. It is highly recommended that you configure this. See Protecting against HTTP HOST Header attacks for more information.

Warning about Trusted Host Settings in Drupal 8

Warning about Trusted Host Settings in Drupal 8

in case you are running a single website, the solution is simple, open settings.php file and add following code:

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

For more complicated use, please see following article:  Trusted Host settings

 

Latest articles

Ādģēri: The 30K Mistake That Turned Into a Long-Term Experiment

In 2023, we bought Ādģēri in an online auction.Price: just over €30,000.Financing: ~6% interest.Total expected payment over ~5 years: ~€40,000.Status (April 2026): more than half already paid.On paper, it was a bad deal.Realistically, we overpaid by at least 5–6× relative to what the property was objectively worth at the time. No serious buyer…

Ādģēri |

Berlin Zoo and Aquarium: One of the Best Things To Do in Berlin With Kids

At the start of April 2026, during our roughly five-day trip to Berlin, we finally visited the famous Berlin Zoo for the first time - or at least the first time I can actually remember. There is a chance my mom might have taken me here sometime in the early 1990s, but if so, those memories are long gone. This visit felt completely new, and…

Germany |