In the past with Drupal 6 (I have skipped 7 so far), I ran various sites with a common codebase using the following structure:

sitename.com
  |
  |--cms (symbolic link to drupal directory)
  |
  |--Other stuff I might want on the site

i.e. in each site, there was a subdirectory called CMS that was actually a redirect to the base Drupal folder.

I liked doing things this way, as it let me (if required) install other stuff on the same domain without it messing with the main Drupal install.

I then used a custom .htaccess file in the base website directory to redirect all traffic to the /cms directory, but to re-write the URL, so that it still appears that Drupal is running in the base directory.

In Drupal 6, this worked fine.
In Drupal 8 though, it works fine up to a point. I can go to the site & the re-write rules work, but then every now & then, when I am altering settings I get a response:
Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it.

Generally if I get that response, then I insert /cms/ into the url & try it again & it works.

Part of the issue is that I can't see anywhere obvious to set the base URL of the site in the way that there was with Drupal 6 where the
$base_url = 'http://www.mysite.co.uk';
section would set the base URL

Is there an equivalent to this in D8? Is there a way within D8 of telling it to use (or not to use) the www at the start of the URL or to set the base URL for the site?

My current .htaccess is something like this:

RewriteEngine on
Options +FollowSymLinks

# Remove www. at start of address if present
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.mysite.co.uk$ [NC]
RewriteRule ^(.*)$ http://mysite.co.uk/$1 [R=301,L]

# Redirect root page to drupal home (if desired)
# NOTE: without trailing slash, external redirect to /cms will
# be used and it will show up in browser. With slash, hidden.
RewriteRule ^$ cms/ [L]

# Rewrite non-file/directory URL's to be under drupal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ cms/$1 [L]

Any suggestions would be welcomed.

Comments

mat8iou’s picture

I've tried adding the code mentioned here:
https://www.drupal.org/node/2619432#comment-11012323
to the end of the settings.php file.

It seems to sort of fix the problem - but it would still be nice to be able to do it entirely in the .htaccess file rather than having to alter the settings file.

It also needs a lot more testing to convince me that I have actually fixed the issue & it won't pop up again at some future point.