I'm running Windows 7 64bit with WampServer 3.1x (also 64bit) to do my Drupal 8.3.4 development work. I need some insights into how to use an alias with Drupal 8.3.4.

In my HOSTS file, I have the following entries:

::1 localhost.foobar.com #Pre-existing Drupal 7 project.
::1 localhost.d8.foobar.com #The Drupal 8 project I'm trying to work on.

When accessing my Drupal 8 install in the URL via "http://localhost/projects/foobar_drupal_8/," everything works as expected. But as soon as I try to access "http://localhost.d8.foobar.com/user," I get the following error:

Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it.

After researching things, I came to learn that this is due to a security measure that D8 has to prevent spoofing. Okay, so thinking that "localhost.d8.foobar.com" needs to be placed in the "$settings['trusted_host_patterns']" array (as others have suggested in other similar cases I found on Google), I added the following to the array in /sites/default/settings.php:

$settings['trusted_host_patterns'] = [

...but after doing this, I then attempt to go to "http://localhost.d8.foobar.com" where I get the following error:

The provided host name is not valid for this server.

At that point, the alias and "http://localhost/projects/foobar_drupal_8/" no longer function and to make the latter at least work, I have to remove the array entry I made above. So frustrating!

Long story short, all I'm trying to do here is use a domain alias on my local web server... It was pretty easy to set up in D7 but now in D8, it seems like a nightmare.

What am I doing wrong here?


mmjvb’s picture

Obviously, the host is not in the trusted pattern:
localhost.d8.foobar.com is not matched by ^foobar\.com$.

^foobar\.com$ only matches footer.com and nothing else!

The pattern you need is: ^localhost\.d8\.foobar\.com$

Wolf_22’s picture

mmjvb’s picture

The pattern I provided doesn't allow localhost. A matter of adding a line with ^localhost$

Wolf_22’s picture

Hmm... I guess I never thought you'd have to explicitly indicate that you would want to allow the site to be accessed by the system it's being served from. (Maybe I'm misinterpreting what it's doing?)

Regardless, that did the trick. Thanks!