Another variation on multisite installation and clean URLs
I've read though a lot of other posts on getting multisite setups working and on getting mod_rewrite working. I can get either one but not both. Here's my setup: I have hosting with 1and1, and my configuration looks kind of like this:
primary_domain_docroot
|
|
+-- cms
|
+-- site1a.com/cms*
|
+-- site2a.com/cms*
|
+-- site3a.com/cms*
So primary_domain is a big long name that's no real use to me, but it's important because it means that all these directories can be served by Apache. The other sites are the ones I actually pay for and use, I believe the correct term for these is an 'add-on domain'. I've set each site to have its root at a directory with the same name as the site.
Each of the cms* items is a soft link back to primary_domain_docroot/cms, which corresponds to a real directory on the server. At the root of each of site1a.com, site2a.com and site3a.com (siteXa.com for short) I have an .htaccess file that just redirects to its own cms* softlink. That'd be primary_domain_docroot/site1a.com/.htaccess, for example. This in turn serves up the correct site. Of course each of these sites is configured under primary_domain_docroot/cms/sites/.../settings.php.
I also have an .htaccess at primary_domain_docroot/cms/.htaccess which handles clean urls properly as long as the urls are under siteXa.com/cms. To achieve this I use "RewriteBase /cms" in that .htaccess. All is well except that I have this extra /cms/ stuff at the start of all my urls.
Now I'm trying to set up another few sites (not that the first few have been a rousing success, but you live and you learn). I'd like to keep the current functionality and add the new sites. I'd like the new sites to be completely run by drupal (I don't want the /cms/ part), and I want clean urls . At the same time I'm trying to add another subdirectory under the same drupal install. The layout will look something like this:
primary_domain_docroot
|
|
+-- cms
|
+-- site1a.com/cms*
|
+-- site2a.com/cms*
|
+-- site3a.com/cms*
|
+-- site1b.com/
|
+-- site2b.com/
|
+-- site3b.com/
|
+-- site1c.com/xyz
The only thing that exists is site1c.com: site1c.com/xyz is new and so are siteXb.com.
I can make everything work fine without clean urls, but some parts shown might have had to be replaced by symlinks (don't recall - I broke it all now). I've tried a whole lot of finagling in .htaccess to get site1c.com/xyz to work with clean urls.
My reasoning so far is that I have to make site1c.com/xyz a directory so it can contain a .htaccess that does the necessary mod_rewrite. I can't get all the mod_rewrites into primary_domain_docroot/cms/.htaccess, can I? If that's the case then I could just make all the sites symlinks and be done. The setup I think I need has new symlinks to primary_domain_docroot/cms under each of siteXb.com and site1c.com/xyz. I really don't know any more though.
Ideas?

Figured it out
I've amazed myself here and figured out this thing. The key was this bit (to quote myself):
"I can't get all the mod_rewrites into primary_domain_docroot/cms/.htaccess, can I?"
I can and I did. So all the directories that I want to be run by drupal are just soft links to the same code installation. Here's my directory structure:
primary_domain_docroot
|
|
+-- cms
|
+-- site1a.com/cms*
|
+-- site2a.com/cms*
|
+-- site3a.com/cms*
|
+-- site1b.com*
|
+-- site2b.com*
|
+-- site3b.com*
|
+-- site1c.com/xyz*
Everything marked with an asterisk (*) is a symlink (ln -s) to primary_domain_docroot/cms. To get clean urls to work, the mod_rewrite part of my .htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
# for www.site1c.com/xyz
RewriteCond %{HTTP_HOST} ^www.site1c.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /xyz/?q=$1 [L,QSA]
# for www.siteXa.com/cms
RewriteCond %{HTTP_HOST} ^www.site1a.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.site2a.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.site3a.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/?q=$1 [L,QSA]
# all other vhosts - www.siteXc.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?q=$1 [L,QSA]
</IfModule>
I've changed the names of the sites of course, so I hope I didn't bungle anything in the search and replace, but this is otherwise the same as what I'm using for a multisite install with clean urls. Basically the key was to get the single .htaccess checking %{HTTP_HOST} to see which site it is, then rewriting accordingly. It was complicated by the fact that you only get one RewriteBase directive per .htaccess. Otherwise I think it could be simplified.
I don't get why rewriting to /index.php?q=x doesn't work but rewriting to /?q=x does, but that was my hangup for a long time. I found this tip on wmw to be helpful while debugging http://www.webmasterworld.com/forum92/5360.htm, specifically the bit about replacing rewrites with redirects:
RewriteCond %{QUERY_STRING} !vardumpRewriteRule (.*) http://www.example.com/$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST} [R=301,L,QSA]
I used this with the Live HTTP Headers extension for Firefox to see where things were going.
Hope this saves someone else pulling their hair out for hours on end.
I have been perpetually
I have been perpetually postponing a multi-site install, so this tip sounds very promising. Just to clarify:
1.) You only have one drupal install in your web root (public_html)
2.) You only have one db? Did you use db_prefix then?
3.) What about settings.php?
Just one copy of the code
1) The only install of drupal is under primary_domain_docroot/cms ( a real directory).
2) I actually have two databases used for the sites, some of siteXb.com will share user tables. All sites use database prefixes. I used a sed script I found on drupal.org and some manual review/massaging to get the prefixes on all the drupal tables and tables needed for some extra modules.
3) settings.php has the appropriate base urls, database prefixes and other stuff for each site (I'm willing to post specific pieces, but don't have access to it at the moment). The settings.php part was easy (lots of references for that), it's the clean urls part that was a pain. Oh, and of course there's a settings.php for each site.
Thank you very much for the
Thank you very much for the clarifications. Just one more thing. Is the sed script crucial to this whole thing or is it optional?
Not necessarily sed
It's crucial that your database prefixes be correct, if you use prefixes. It's not crucial that you use a particular sed script to do that.
If you have a separate database for each site, then you don't need prefixes - this is the easiest route. If you share all the tables for all the sites (which you probably don't want to do) then you don't need prefixes.
If you have multiple sites sharing one database but you want those sites to have different content, then you need to set up the correct table prefixes in each site's settings.php and in the SQL that you use to create the tables. This also applies to tables created for modules that you add later. There are plenty of examples of how to do this on drupal.org, just the one that I found a while ago happened to use a sed script.
Drupal Multisite Clean URLs Work!
I got it working by ...
1. Adding the following to my vhost.conf:
AllowOverride All</Directory>
2. Uncommenting RewriteBase in .htaccess:
RewriteBase /3. Adding a forward-slash (before index.php) in the RewriteRule in .htaccess;
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]</IfModule>
4. Restarting apache, of course.
step 2 and 3: which
step 2 and 3:
which .htaccess, the base or the .htaccess in the /sites/domain.com/.htaccess?