Having trouble with a non-standard configuration of Drupal 9 and relatively new to Drupal as a whole.

I'm looking to have a few Drupal 9 sites all live off the same root domain, for example:

  • Drupal Site 1 accessible at /site-one
  • Drupal Site 2 accessible at /site-two
  • Drupal Site 3 accessible at /site-three

I've managed to get this roughly working by renaming the web folder to site-one and having a symbolic link created called web pointing to site-one. Changing the RewriteBase to /site-one as well and it mostly works. Since the DocumentRoot doesn't point to the web folder some files are accessible that shouldn't be but changes to .htaccess solved that for the most part.

Is this the preferred way to do this? Is there any setup where we can have multiple Drupal sites all accessible off the same domain but under their own sub-folders (instead of sub-directories, site-one.example.com doesn't work for this use case).

Comments

gisle’s picture

If you just want to have more than one site in sub-folders (example.com/site-one), you just need to configure your web-server to point to the webroot below that sub-folder as the DocumentRoot (e.g.: /var/www/example.com/site-one/web). If you want to use a sub-domain (sub-domains (site-one.example.com), configure your zone-file with a CNAME to point to this subdomain and you may set up /var/www/site-one.example.com/web as your webroot. Configure that as your DocumentRoot in your webserver configuration. All this is standard Apache and DNS configurtion, and have nothing to do with Drupal. You would do the same type of configuration to have several WordPress sites in sub-folders or in sub-domains.

Drupal let several websites share the same code base, but with different content. This is known as a "multi-site" and you can learn more bout it here: https://www.drupal.org/docs/multisite-drupal

- gisle

mmjvb’s picture

The preferred way is to configure each of the parts the right way. Not to manipulate the last part because you don't want to touch the other parts. You might not be allowed or just don't know how to, which makes you needing to do it. 

Downloading from drupal.org gets you a setup based on drupal/legacy-project, that means without the web folder. It already contains hardening.

Would recommend adjusting web in composer.json rather than renaming and symbolic link. There are distributions calling web html or even docroot.

So, with a legacy setup, you only need a RewriteBase to the site-number in each.

With a recommended-project setup you could provide an Alias (in VirtualHost) for site-number pointing to the web folder and RewriteBase.

Not sure why you claim sub-domains (not sub-directories) don't work for this use case. They always work, they might not be what you want. Sounds like your provider doesn't allow you to configure the web server for serving multiple sites (VirtualHost).

When you don't mind the single code base, multisite setup of drupal might be for you. Note, that is a different setup. One code base for your domain for as many sites as you want. Not every site having its own code base.

loken’s picture

Thanks, I clearly just needed more coffee and some helpful words to remind me!