It can be done. And it's not that hard.

What we're talking about is starting with an existing Drupal installation–call it www.example.com–and adding another Drupal site, with its own content, themes, modules, and configuration BUT using the same Drupal code as the original site (i.e., not duplicating the Drupal files themselves), to be accessed at a subdirectory URL such as www.example.com/secondsite. The advantage of running more than one site off the same code base is that it's a LOT easier to maintain/upgrade.

I'll go though the steps for adding one site to your existing installation. You can add as many more sites as you want, by repeating these steps.

Let's assume you have Drupal installed in /public_html. This is just to simplify the instructions below; if you have it installed in a different directory, just substitute that directory for 'public_html' in what follows.

First, let's go through the steps provided in install.txt (http://api.drupal.org/api/file/INSTALL.txt/5/source):

In the /sites directory of the existing installation, create a new directory, /www.example.com.secondsite (so you now have /public_html/sites/www.example.com.secondsite). Obviously, you can replace "secondsite" with whatever you want, as long as it's not the name of a directory that already exists in /public_html, e.g., not "includes" or "modules," etc. Inside that new directory, place a "clean" version of settings.php. "Clean," in this case, means unmodified from the one originally provided in the Drupal download.

Now, modify 2 lines in that new settings.php file (for v5, should be lines 93 & 94 or thereabouts): the database connection line ($db_url), and the table prefix line ($db_prefix). The $db_url line should be changed so that it is the same as in the current settings.php in your main Drupal site. The $db_prefix line must be changed so that when Drupal creates the tables for the new site, they will all have a distinctive prefix. That way, you can have two (or more) full sets of Drupal tables without naming conflicts. Use something appropriate for the prefix; for secondsite, I might use 'ss_', or something similar.

Now add a block to your .htaccess file, like so:

  # Rewrite current-style URLs of the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/secondsite/.*
  RewriteRule ^(.*)$ /secondsite/index.php?q=$1 [L,QSA]

...where you substitute, obviously, the name of your subdirectory for 'secondsite.' This new block should go ABOVE this one (which should already be there):

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

According to install.txt, you are now done, and you can go to http://www.example.com/secondsite/install.php to set up your new site.

But you AREN'T DONE. The next step is crucial.

Create a virtual directory in the directory where Drupal is currently installed, named 'secondsite' (or whatever it was you called it), and point that back to /public_html. You can do this yourself if you have administrative access to IIS; failing that, a nice email to support at your Web host may get the required results.

NOW you can go to http://www.example.com/secondsite/install.php and set up your new site.

You may read elswhere that you need a symlink to accomplish this last step. Here's my experience with that: The "symlinks" created by Winbolic just don't work. And you don't want to use junctions (the closest Windows equivalent to symlinks) because, according to my sysadmin anyway, if you point point a junction back to its parent directory like that, you will get an infinite recursion in the case of searches, backups, etc. And that would be a Bad Thing.

You can also create additional Drupal sites that use subdomains, or even completely different domains, by following the same steps except for that last one, and just pointing those domains or subdomains to the Drupal directory. This is adequately spelled out in install.txt except for that last detail (the pointing).

I hope this helps someone. I spent literally days sifting through posts here, trying to solve this problem. As soon as I suggested using junctions to my sysadmin, though, he put on his thinking cap and came up with this solution.

Comments

willow315’s picture

I've followed your directions to the letter, and gotten some advice from others. No luck. I can't get IIS to recognize the virtual directory. I just continue to get 404 or 403 errors no matter what I try.

The only thing different I'm doing is that I've moved over some themes into the all directory. Because what I'm actually trying to do is get a site that was already set up else where to appear as a second site as second site after I just installed the primary Drupal, which is still raw.

HELP!!! Or anything you can aim me to for getting separate installations.....Subdomains etc. I dont' care. I just have to get this second site on the test server....ASAP.

Thanks in advance. WCW

zbricoleur’s picture

So, you have a folder in /sites named 'www.mysite.com.mysubsite'
And in that folder, you have a settings.php file with the appropriate settings for mysubsite's database connection.
And you have a virtual directory named 'mysubsite', which is in the main Drupal folder and is pointed back at the main Drupal folder.
Is that correct?

rdahiya’s picture

Will using a separate DB for the "secondsite" work?

zbricoleur’s picture

Yes, that will work.

RTauson’s picture

Trying to do this on a linux server using a symbolic link, just as mentioned in the main instructions I got a redirection loop.
Is a symbolic link in linux the same as a virtual link in windows ? If it is does anybody now how to correct the redirection loop ?

zbricoleur’s picture

This probably isn't the best thread for your question, but...where is the symlink and where is it pointing?

Also, I'm realizing that there is an important step left out above (EDIT: I have since added it, but I'm leaving this here, too, just in case). I think it's covered elsewhere in the documentation, but it should be added here. You have to add a block to your .htaccess file, like so:

  # Rewrite current-style URLs of the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/mynewsubdirectory/.*
  RewriteRule ^(.*)$ /mynewsubdirectory/index.php?q=$1 [L,QSA]

...where you substitute, obviously, the name of your subdirectory for 'mynewsubdirectory.' This new block should go ABOVE this one (which should already be there):

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
hemant.kamalakar’s picture

Hello Sir,

I followed this one.

I tried to create alias and then pointed the virtual directory back to main Drupal Installation.
After that when i Browse my new site i am getting message as Drupal is already installed.

Below are the steps which i did please go through this. So that you will be know where i was wrong.
1. my site is hosted as http://test.mysite.com/demo. Demo folder contains my default Drupal installation and working fine.
2. Created new folder under http://test.mysite.com/demo/sites as test.mysite.com.demo.demo1
i.e. http://test.mysite.com/demo/sites/test.mysite.com.demo.demo1
3. Then created virtual directory named demo1 into main Drupal installation directory under http://test.mysite.com/demo.
4. Then demo1 pointed back to the main drupal installation folder i.e. http://test.mysite.com/demo

After that i tried to browse http://test.mysite.com/demo/demo1 then i got message as Drupal is already installed.

Can you guide me on this. Where i am wrong?

Also i am little bit confused about how to point virtual directory in the directory where Drupal is currently installed, named 'demo1' in my site to the main drupal installed directory i.e. http://test.mysite.com/demo in my site.

Waiting for your reply.

I am using Drupal 6.5 and site is hosted on Windows2003 server using IIS6.0

Hemant

zbricoleur’s picture

From what you've said, I'm going to guess that the settings.php file in the test.mysite.com.demo.demo1 folder is identical to the one in the default folder. If so, then you have set things up so that the new site uses not just the same database, but the same tables.

Assuming that my assumption above is correct, and that what you are trying to achieve is a *different* site at the new location, you would need to change the db_prefix line in the test.mysite.com.demo.demo1 settings.php to something different from what you have in the default settings.php file. For instance, if the default file has

$db_prefix = '';

then change the test.mysite.com.demo.demo1 file to

$db_prefix = 'demo_';

That way, Drupal will know that it needs to create a new site for test.mysite.com.demo.demo1.

umar.adil’s picture

Hello sir

I followed all the steps mentioned above

My Drupal is installed on local machine as http://localhost/drupal

I created a new site as site1.com in

/htdocs/drupal/sites/site1.com/

and copied the default settings file in site1.com

I have also created a virtual host in my apache for the site1.com

but it is not recognizing my site1.com and is opening site1.com by DNS

Please help.

zbricoleur’s picture

First, these instructions are for IIS, not Apache.
Having said that, I think you'll have to change your hosts file if you're trying to set this up on localhost. Otherwise, your DNS server is going to direct you to the real site1.com if it exists.

maritaca’s picture

I don't manage to create a 2º functional Drupal in a subdirectory

I've got 1º site in Drupal in root with clean urls

And the 2º site in /mysite with clean urls, the problem is that the install was correct,
but now the login page appears without images, and if I want to login:
the admin page go to error not found.

I use module Isapi Rewrite 4 and IIS 6, my IsapiRewrite.ini is like this one

RewriteLog C:\PathToYourIsapiRewriteFolder\
RewriteLogLevel 3
RewriteFilterPriority HIGH

#Accept a url with the following directories and pass them through unchanged.
RewriteRule ^/misc/(.*)$ /misc/$1 [I,L]
RewriteRule ^/files/(.*)$ /files/$1 [I,L]
RewriteRule ^/modules/(.*)$ /modules/$1 [I,L]
RewriteRule ^/themes/(.*)$ /themes/$1 [I,L]
RewriteRule ^/sites/(.*)$ /sites/$1 [I,L]
RewriteRule ^/uploads/(.*)$ /uploads/$1 [I,L]
RewriteRule ^/css/(.*)$ /css/$1 [I,L]
RewriteRule ^/images/(.*)$ /images/$1 [I,L]

# for modules that provide their own js (tinymce,img assist etc)
RewriteRule ^(.*\.js)$ $1 [I,L]
RewriteRule ^(.*\.gif)$ $1 [I,L]
RewriteRule ^(.*\.png)$ $1 [I,L]
RewriteRule ^/modules/tinymce/(.*)$ /modules/tinymce/$1 [I,L]

# Make URLs sane
RewriteRule ^/cron\.php$ /cron.php [I,L]
RewriteRule ^/index\.php\?q\=(.*)$ /index.php?q=$1 [I,L]
RewriteRule ^/update\.php\?op\=(.*)$ /update.php?op=$1 [I,L]
RewriteRule ^/update\.php /update.php [I,L]
RewriteRule ^/xmlrpc\.php /xmlrpc.php [I,L]
RewriteRule ^/robots\.txt /robots.txt [I,L]

# Handle query strings on the end
RewriteRule /(.*)\?(.*)$ /index.php\?q=$1&$2 [I,L]

# now pass through to the generic handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /index.php?q=$1 [L,QSA]

# now pass through to the generic handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/mysite/(.*)$
RewriteRule ^/(.*)$ /mysite/index.php?q=$1 [L,QSA]

Please I would appreciate your help.

Thanks

goose2000’s picture

my sub-directory site is called /mchbeta/

The settings files has this, waiting to see if it has been re-written

// Isapi_Rewrite 3.x
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}

My .htacess files look like:

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.56

RewriteEngine on
Rewrite Base /

# Rewrite current-style URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/mchbeta/.*
RewriteRule ^(.*)$ /mchbeta/index.php?q=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Running IIS 6
ISAPI_Rewrite 3.x

Whats odd is other drupal sites outside the multi-site config , that run in a sub-directory
work fine. They seem to do this by setting the RewriteBase /to-my-directory

Ideas?

EDIT, oh and of course if I just set the RewriteBase to /mchbeta - then I can get the sub-site to pass the Drupal clean URL test. I just don't have the right rules or virtual directory set up right...

goose2000’s picture

"Create a virtual directory in the directory where Drupal is currently installed, named 'secondsite' (or whatever it was you called it), and point that back to /public_html. You can do this yourself if you have administrative access to IIS; failing that, a nice email to support at your Web host may get the required results."

So is it just me or are we mixing Martians and Moon-men here? Where am I supposed to "point back to" there is no directory /public_html on a Windoze IIS server, uh last I checked.

zbricoleur’s picture

Let's assume you have Drupal installed in /public_html. This is just to simplify the instructions below; if you have it installed in a different directory, just substitute that directory for 'public_html' in what follows.

Didja really read the whole thing? ;-)

goose2000’s picture

What rewrite software were you using when you wrote this post?
And what version of Windoze server / IIS?

goose2000’s picture

Ok I found the problem. Nice to actually have someone report back they could get this to work, regardless of the confusing allusion to Apache directory structures.

My trouble was simply that my .htaccess file was set to work on the current root directory only.
After commenting that out, the other rules started to kick, my sub site passed the URL test
and it is now a clean multi-site ! Another happy landing.

RewriteEngine on
# RewriteBase /