Sub directory based multisite using XAMPP

Last updated on
27 December 2023

It is not recommended to use XAMPP for local Drupal development. Use a Docker-based solution such as DDEV or Lando instead.

Please find the steps to host a bunch of sites using Drupal's multisite feature in the subdirectories.

To achieve this follow these steps.

  1. Add alias to our Apache configuration file
  2. Redirecting all requests to index.php
  3. Creating our settings.php

Add alias to our Apache configuration file
We want requests for the 3 subdirectories(emea, la, uk) to go to the same Drupal instance.
We can do this using Apache's Alias functionality.

DocumentRoot "C:/xampp/htdocs/drupal"
Alias /emea C:/xampp/htdocs/drupal
Alias /la C:/xampp/htdocs/drupal
Alias /uk C:/xampp/htdocs/drupal

I'm supposing here Drupal's codebase is hosted in C:/xampp/htdocs/drupal on your machine

Redirecting all requests to index.php
Now that we're serving all requests from one codebase we have to redirect all requests to index.php. This needs to be done since all Drupal requests are served from one endpoint, called index.php. So we have to do the below changes in the .htaccess file in the same order as mentioned below.

  # EMEA site
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/emea/(.*)$
  RewriteRule ^(.*)$ /emea/index.php [L,QSA] 
  
  # LA site
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/la/(.*)$
  RewriteRule ^(.*)$ /la/index.php [L,QSA]
  
  # UK site
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/uk/(.*)$
  RewriteRule ^(.*)$ /uk/index.php [L,QSA]
  
  # default site
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L,QSA]

(Note: this should work in both Drupal 6 and 7. You may need to try ending each RewriteRule line with either just [L] or as shown above: [L,QSA] depending on your server setup.)

Creating our settings.php
We can now have different settings (database, ...) for each site by creating a different settings file for each site. Place the settings.php for each file under a directory called after the domain name and subdirectory. In our example we would have the following setting files:

C:/xampp/htdocs/drupal/sites/default/settings.php           - Base site settings
C:/xampp/htdocs/drupal/sites/localhost.emea/settings.php    - EMEA site settings
C:/xampp/htdocs/drupal/sites/localhost.la/settings.php      - LA site settings
C:/xampp/htdocs/drupal/sites/localhost.uk/settings.php      - UK site settings

Now, start installing the site by using the below URLS

Enjoy the Drupal's multisite feature in the subdirectories.

Help improve this page

Page status: No known problems

You can: