Drupal 8 multisite install where

  1. First site is on a subdomain one.example.com
  2. Second site is in a subfolder one.example.com/two

How can files folder for both sites to be accessible via URL/files and not URL/sites/domain/files

  • current: one.example.com/sites/one.example.com/files
  • desired: one.example.com/files
  • current: one.example.com/two/sites/two/files
  • desired: one.example.com/two/files

I tried several variants listed here https://www.drupal.org/node/53705 and put them at following locations, but nothing worked.

  1. Drupal8/.htaccess
  2. Drupal8/files/.htaccess
  3. Drupal8/sites/two/files/.htaccess

Setup information is provided below

Filesystem setup

  --one.example.com (sym link ln -s . one.example.com)
  --two (sym link ln -s . two) Not required in D8, but could not get the subfolder site to work without it.
    --default (sym links to one.example.com)
      --settings.php, services.yml
      --files, modules,etc
      --settings.php, services.yml
      --files, modules,etc


$sites = [];
$sites['one.example.com'] = 'one.example.com';
$sites['one.example.com.two'] = 'two';

Apache setup : One virtual host for one.example.com

  • What did you actually put in /.htaccess that did not work? We use something like: RewriteCond %{HTTP_HOST} ^(foo\.bar\.com RewriteRule ^files/(.*)$ sites/foo/files/$1 [NC,L]
    – cilefen
    Aug 16, 2016 at 18:15
  • I tried RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L, R] and RewriteRule ^(.*)$ /sites/%{HTTP_HOST}/files/$1 [L, R] Which .htaccess file are you adding this to?
    – amit
    Aug 16, 2016 at 18:22
  • The root .htaccess in the site directory, where Drupal is installed. Note, this is an edit of the .htaccess provided by Drupal. Does HTTP_HOST match the multisite directory name in every case on this site?
    – cilefen
    Aug 16, 2016 at 18:26
  • The subdomain site matches the HTTP_HOST, but sub folder does not, as it will be more cryptic (one.example.com.two) and won't match HTTP_HOST anyways. I tried your suggestion to see if at least the subdomain site's files would work, but it did not.
    – amit
    Aug 16, 2016 at 18:47
  • I also tried to hardcode path on subdomain RewriteCond %{HTTP_HOST} ^one\.example\.com$ [NC] RewriteRule ^files/(.*)$ sites/one.example.com/files/$1 [NC,L] this did not work
    – amit
    Aug 16, 2016 at 18:48

3 Answers 3


In /.htaccess, above other rewrite rules, use something like this example for foo.bar.com:

RewriteCond %{HTTP_HOST} ^foo\.bar\.com
RewriteRule ^files/(.*)$ sites/foo.bar.com/files/$1 [NC,L]
  • This works on the site (one) which is on subdomain, but not for the site (two) which is in a subfolder
    – amit
    Aug 16, 2016 at 21:26
  • This worked, as we'll need separate rule for sub folder RewriteCond %{REQUEST_URI} /two/ RewriteRule ^files/(.*)$ sites/two/files/$1 [L] RewriteCond %{REQUEST_URI} !/two/ RewriteRule ^files/(.*)$ sites/%{HTTP_HOST}/files/$1 [L]
    – amit
    Aug 16, 2016 at 21:37

Since in this case one site is on subdomain the other on subfolder, single rule as mentioned by @cilefen is not sufficient. So we need to make two rules in this case, one for the subfolder site and other for the subdomain site. The subfolder site rule is hardcoded as we can't generalize it.

The rewrite rules need to be added to Drupal core's .htaccess (i.e one next to index.php). This will also require changes to .htaccess on every Drupal upgrade as the stock file won't have these rules.

  # Subfolder site
  # match subfolder site url path and amend its file path
  RewriteCond %{REQUEST_URI} /two/files/
  RewriteRule ^files/(.*)$ sites/two/files/$1 [L]

  # Subdomain site
  # if the url path matches subfolder site skip this rule
  RewriteCond %{REQUEST_URI} !/two/files/
  RewriteRule ^files/(.*)$ sites/%{HTTP_HOST}/files/$1 [L]

These rules need to be above the following, else they won't work

  # Pass all requests not referring directly to files in the filesystem to
  # index.php.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

Thanks to @cilefen for putting me on the correct path.


No need for any server config. You can do this by setting $settings['file_public_path'] = 'files'; in both your sites settings.php files.

See default.settings.php (click "View source")

 * Public file path:
 * A local file system path where public files will be stored. This directory
 * must exist and be writable by Drupal. This directory must be relative to
 * the Drupal installation directory and be accessible over the web.

# $settings['file_public_path'] = 'sites/default/files';

Your Answer

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

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