- Issue created by @vinodhini.e
First, you may have a better support experience on Slack.
Was the DDEV software documentation helpful or did you have to make the customizations based on your own knowledge of Drupal and nginx?
What does the DDEV configuration file look like?
Is this answer helpful?
At a glance it is because the default site exists and the web server hasn't been configured to handle that.
- ๐ฎ๐ณIndia vinodhini.e chennai
Hi @cilefen #3,
Thanks for the quick response and for sharing the article. We're currently working on implementing a multisite setup using subfolders, and while the article you provided covers basic subfolder configurations, our specific need is for a folder-wise structure within the sites path.Here's our DDEV configuration, and you'll find the folder-wise structure reflected in the sites path. Our goal is that when we access http://my-drupal-multisite.ddev.site/site1, it should correctly redirect to site1.
DDEV Configuration
----------------------------------
name: my-drupal-multisite
type: drupal
docroot: web
php_version: "8.3"
webserver_type: nginx-fpm
xdebug_enabled: false
additional_hostnames:
- "my-drupal-multisite.ddev.site.site1"
- "my-drupal-multisite.ddev.site.site2"
additional_fqdns: []
database:
type: mariadb
version: "10.11"
use_dns_when_possible: true
composer_version: "2"
web_environment: []
corepack_enable: true
default_container_timeout: "240"Any suggestions you might have would be greatly appreciated.
Thanks in advance!
- First commit to issue fork.
- ๐ฎ๐ณIndia mpmano
Prepare the Multisite Directory Structure
Create folders for each subsite under web/sites/:bash mkdir -p web/sites/site1/files mkdir -p web/sites/site2/files cp web/sites/example.settings.php web/sites/site1/settings.php cp web/sites/example.settings.php web/sites/site2/settings.php
Create Symlinks for Subdirectory Access Important Step
This is the key step that enables subdirectory access:cd web # Symlink site paths to index.php ln -s . site1 ln -s . site2
Note: Use ddev ssh and create symlink using the above command if you are using ddev environment.
Configure sites.php
Create a sites.php file using this command ->
touch web/sites/sites.php
Edit or create web/sites/sites.php:
php<?php $sites = [ 'example.ddev.site.site1' => 'site1', 'example.ddev.site.site2' => 'site2', ];
Drupal converts subdirectory URLs like /site1 into example.ddev.site.site1 internally for multisite resolution.
Configure Database Connections
Edit each site's settings.php to define the correct database.
Example: web/sites/site1/settings.php$databases['default']['default'] = [ 'database' => 'site1', 'username' => 'db', 'password' => 'db', 'host' => 'db', 'port' => 3306, 'driver' => 'mysql', ];
Repeat similarly for site2.
Set File Permissions
chmod -R 775 web/sites/site1/files chmod -R 775 web/sites/site2/files
Enable .htaccess Rewrite Rules for Subdirectory Sites
Drupalโs default .htaccess is designed for single-site setups. For multisite with subdirectories, we need to ensure Apache knows how to handle requests like /site1/node/1 properly.Add Rewrite Rules to Top-Level .htaccess
Edit or append to the top of your web/.htaccess:
apache# Multisite Subdirectory Rewrite Rules RewriteEngine on RewriteBase / # Uncomment this line RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteCond %{REQUEST_URI} ^/site1 RewriteRule ^ site1/index.php [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteCond %{REQUEST_URI} ^/site2 RewriteRule ^ site2/index.php [L]
This ensures:
example.ddev.site/site1/node/1 โ routed through site1/index.php (symlinked to ../index.php)Clean URLs (like /site1/about) resolve properly.
Don't Remove Existing Drupal .htaccess Rules
Run:
ddev/apache restart
Apache will now recognize .htaccess changes.
Install Each Site via Browser
Visit each site in your browser to begin installation:
http://example.ddev.site/site1/core/install.phphttp://example.ddev.site/site2/core/install.php
Follow the on-screen prompts to complete installation.
Test the Multisite Setup
After installing:
Go to http://example.ddev.site/site1 โ should load Site 1.Go to http://example.ddev.site/site2 โ should load Site 2.
Hope this will help.
- ๐ฎ๐ณIndia vinodhini.e chennai
@Mano, I followed your steps and was able to set up the multisite successfully. Thanks.