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.
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.
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]
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
Comments
Not sure where/how this method applies to what I'm trying to do, but hoping it could translate... I have a D7 site (part of a multi-site install) where the 'owner' actually wants to have the url be newsite.mydomain.org/myStupidDirectory/. Since it doesn't matter where the drupal files actually are, it looks like your method might work, but I don't see where the alias lines should go in which apache conf file. It's kind of modular, with vhost stuff in sites-avail, etc. and I'm wondering if some form of aliasing could be done there instead. Likewise with rewrite rules. And would anything need to be done at the sites.php level - besides making sure the 'domain'=directory line agrees with what's done elsewhere? I would just hack at it, but there are people trying to develop on several of the sites and I don't want to keep disabling the server.
You know, honestly I'm starting to think that some competitor to Drupal out there is posting frustrating garbage posts to mislead us all and make it seem impossible to do anything... ninety percent of the posts here are just nonsense.
Can someone help with me setting up drupal multisite? I have posted at drupal forums but no luck.
URL: http://drupal.org/node/1083320#comment-4176692
Originally I was following the INSTALL.txt that comes with drupal but I can't get it work on a sub-folder.
Thank you.
C
I copied yours in .htaccess of my main drupal installation. The original rewrite script in .htaccess file works fine. I changed the RewriteBase from / to /subdir1, it worked. But, do the reversed thing as I described above. e.g. when set to use clean urls in main drupal. it brings me to the log in page of my sub-folder installation.
I have tried this every way under the sun. The best I get is a directory index of my sub site. If I use subdomains everything works fine, but when I try to access my second site 192.168.1.5/site I get and index. I also placed a test index.html in the second site and it displays fine. Just cant get the sub directory site to install.
Any advice?
Successfully deployed the above, but am now having issues with the boost module with multisite installed in subfolders. Please refer to the issue http://drupal.org/node/1044814 - any help there would be appreciated
However, I'm a little reluctant to assume that everything will "just work". Primarily because I don't understand how Drupal is able to distinguish the session cookies from testinside With multisite subdomains, I can understand it (the browser keeps cookies from each subdomain separate). How is it able to work with multisite subDirectories? Has anyone run into any problems?
Great post, very helpful, I have to say that if ones web site like this on of Target was so unhelpful to the client using it, why would this client come back, or even tell anyone else to use it. This can be very damaging to a business hp ais in the long run.
Can this install work with sub-domains?
If I'm running this on a development server, can I use a temporary URL or the dev server IP address in my multisite directory names?
For example, my end URL is going to be mysite.com. mysite.com is already being used at server1.
I'm working on server 2 which currently just has an IP address. How difficult is to change things over?
The trick is RewriteRule Install Ineternet Bussines and Helmets Poles RewriteBase. In fact, in my case, I found Video Effects that your Rewrite script did not affect anything Optimizing Jamoola Content. I copied yours in .htaccess of my main drupal installation
Anyway in the end I realised that even though I don't want to use the i18n features to link translations of a certain page together, nevertheless I can just run it all from the one site. Using i18n URL prefixing the various pages will end up in /fr/... or /de/... depending on what language they are, and this makes my life easier as I only have to manage one site instead of 5.
Get cheap vps hosting from top of hosting provider.
durpal is protecting the sites from those who violates the rules
I think its is positive attitude
braindumps
Worked like a charm.
Thanks.
This method works for me, which is great!
However, I'm a little reluctant to assume that everything will "just work". Primarily because I don't understand how Drupal is able to distinguish the session cookies from /drupal_1 and /drupal_2.
With multisite subdomains, I can understand it (the browser keeps cookies from each subdomain separate). How is it able to work with multisite subDirectories? Has anyone run into any problems?
Cheers!
RC
I create multiple website follow your steps, but how to sharing the session on this multiple website, let user can access all multiple website.
the .htaccess piece was what I was missing to get clean urls working. made my day, thanks!
How can I do in Window WAMP server?
http://localhost/site1
http://localhost/site2
can anyone tell me how can i create symbolic link on my server not my host using php script.
Are you sure that the clean url will work for both www.mysite.com and www.mysite.com/subdir1?
I had problems with alias. I get it working in a simpler way:
My drupal is under /var/www/drupal and I want 2 diferent sites at myserver.com/site1 and myserver.com/site2
I only need 2 simple steps:
1.-Create var/www/drupal/sites/myserver.com.site1, copy settings.php inside and setup database conection string at settings.php
2.-Create simbolic links at /var/www
sudo ln -s /var/www/drupal /var/www/site1
sudo ln -s /var/www/drupal /var/www/site2
And nothing else. It works perfectly.
Update to my own post and apologize to the original author Davy Van Den Bremt. You method works partially. I can now have both my main drupal and sub-folder drupal work following your method. However, the clean urls function does not work on the subfolder. I can select "enable" under Administer/Site configuration/Clean URLs in my sub-folder installation. But after I clicked "Save configuration", it brings me to the login page of my main drupal installation, and says "Access denied. You are not authorized to access this page.". The URL showed in browser was still /subdir1/admin/settings/clean-urls.
The trick is RewriteRule and RewriteBase. In fact, in my case, I found that your Rewrite script did not affect anything. I copied yours in .htaccess of my main drupal installation. The original rewrite script in .htaccess file works fine. I changed the RewriteBase from / to /subdir1, it worked. But, do the reversed thing as I described above. e.g. when set to use clean urls in main drupal. it brings me to the log in page of my sub-folder installation.
My test indicates that your way does not work.
It can find index.php file, but I always get a "page not fond" error when I visit
http://www.mydrupalsite.com/subdir1
The only way that I found works is create a symlink back to the home directory where drupal is installed, as Boris Mann suggested.
I have drupal installed at sub directory http://www.m4manas.com/6 I am able to access the site.
Now, i want to have multi site facility in this setup using same code base. I have installed a test site in sites/test
and modified following
1. .htacess to tell that drupal base is /6\
2. Update .htacess with the code
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/test/(.*)$
RewriteRule ^(.*)$ /test/index.php?q=$1 [L,QSA]
3. $base in settings at sites/test to show that the base is /6
4. Create a symlink pointing to base path
I am getting page not found error please help.
in htaccess:
RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(\w+)
RewriteRule ^(.*)$ /%1/index.php?q=$1 [L,QSA]
This will work so long as each subdirectory contains only alphanumeric characters. (another regex might be more versatile, but it must stop at the first slash.)
With this you don't have to edit your .htaccess every time you add a site.
I have, but sometimes it lets something slip through.
You may want to install the free mollom version to avoid comment spam like the one above.
You don't need to alias or change rewrites, you can just create a symlink in /var/www. So, ln -s /var/www /var/www/subdir1.
As well, in sites, the dot is the correct separator for subfolders -- sites/mydrupalsite.com.subdir1
I updated the multisite documentation to make this clearer: http://drupal.org/getting-started/6/install/multi-site
That page could use further editing. Please add your edits!
There perhaps is another way to do this that is simpler: no need to change Apache settings or Drupal rewrite code. First, install Drupal under the web root directory (e.g., drupal_site). Then, create site-specific folders in the following format:
cp -R drupal_site/sites/default/ drupal_site/sites/mysite.com.drupal_1
cp -R drupal_site/sites/default/ drupal_site/sites/mysite.com.drupal_2
Give each site-specific folder its own settings.php and database. Finally, make symbolic links from the web root directory to the site-specific folders, where the symbolic links are given your desired subdirectory names:
ln -s drupal_1 drupal_site
ln -s drupal_2 drupal_site
Now you can browse to mysite.com/drupal_1 and mysite.com/drupal_2 and get different sites. There are probably limitations to this approach, but it worked for me. One limitation may be that some platforms don't support symbolic links (e.g., Windows -- I don't know if shortcuts would be interpreted similarly by the web server.)
Redirecting all requests to index.php
Are you doing this in the .htaccess in the Drupal root?
Post new comment