We all know you can run several Drupal sites using a single codebase. This is done using Drupal's multisite feature. Most of the time you want to host all sites on a different domain name. There's a lot of documentation on how this can be accomplished.
But sometimes you want to run the sites in a subdirectory on one domain. You may want to do this to run a development server for a multisite. You can host all sites in a subdirectory then. This can be easily done with some extra Apache configuration.
Suppose your domain name is mydrupalsite.com. You want to host a bunch of site using Drupal's multisite feature in the subdirectories
http://www.mydrupalsite.com/subdir1
http://www.mydrupalsite.com/subdir2
http://www.mydrupalsite.com/subdir3
You have to do 3 things.
Add alias your Apache configuration file
We want requests for the 3 subdirectories to go to the same Drupal instance. We can do this using Apache's Alias functionality.
Alias /subdir1 /var/www
Alias /subdir2 /var/www
Alias /subdir3 /var/www
I'm supposing here Drupal's codebase is hosted in /var/www 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.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/subdir1/(.*)$
RewriteRule ^(.*)$ /subdir1/index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/subdir2/(.*)$
RewriteRule ^(.*)$ /subdir2/index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/subdir3/(.*)$
RewriteRule ^(.*)$ /subdir3/index.php?q=$1 [L,QSA]
Creating our settings.php
You 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:
/var/www/sites/mydrupalsite.com.subdir1/settings.php
/var/www/sites/mydrupalsite.com.subdir2/settings.php
/var/www/sites/mydrupalsite.com.subdir3/settings.php