Hi all,

I have several multisites setup. (domain.com, domain.com/sales, domain.com/web)

domain.com is the default site located in sites/default
domain.com/sales is a secondary site located in sites/domain.com.sales
domain.com/web is a secondary site located in sites/domain.com/web

(not actual folder names, but similar for example)

The sites share some tables. The following is the setup for each site:

<?php
    $table_prefox
= "sales_"; //this alternates between sales/web/home for the three sites
   
$db_prefix = array(
       
'default'                   => 'shared_',
   
'blocks'                    => $table_prefix,
   
'blocks_roles'           => $table_prefix,
       
'cache'                     => $table_prefix,
       
'cache_filter'              => $table_prefix,
       
'cache_menu'                => $table_prefix,
       
'cache_page'                => $table_prefix,
       
'comments'                  => $table_prefix,
       
'forum'                     => $table_prefix,
   
'menu'                        => $table_prefix,
       
'node'                      => $table_prefix,
       
'node_access'               => $table_prefix,
       
'node_comment_statistics'   => $table_prefix,
       
'node_counter'              => $table_prefix,
       
'node_field'                => $table_prefix,
       
'node_field_instance'       => $table_prefix,
       
'node_group'                => $table_prefix,
       
'node_group_fields'         => $table_prefix,
       
'node_revisions'            => $table_prefix,
       
'node_type'                 => $table_prefix,
       
'variable'                  => $table_prefix,
       
'url_alias'                 => $table_prefix
   
);
?>

The default site is called drupal-home, the others drupal-sales and drupal-web.

The problem is with clean URLs, which work fine for the drupal-home (default) site, but don't work correctly for the other sites.

If I attempt to go to domain.com/admin/settings/clean-urls (default site : drupal-home), everything works fine and I'm presented for the clean URLs options for the drupal-home site. If I go to site.com/sales/?q=admin/settings/clean-urls I'm presented with the options for the drupal-sales site (all good at this point), but enabling the options forwards me to the drupal-home version of the same page and the clean URLs do not get enabled for the drupal-sales site.

I tried manually enabling the clean URLs through $conf['clean_url'] = 1; for each site, and it doesn't quite work. Going to site.com/sales/admin/settings/clean-urls shows me the drupal-home version of the page, rather than the drupal-sales one.

What could be the problem?

Thanks!

Comments

How did you make the URL http://site.com/sales invoke Drupal? Did you use a symlink or another method?

When you browse over the links in http://site.com/sales do they seem correct? Are they like http://site.com/sales/?q=something ?

Hi cog.rusty,

Yes I used symlinks to invoke Drupal.

When I go to site.com/sales, the links are fine. They are in the form you specified, http://site.com/sales/?q=something.

I can go to any admin page just fine (as long as it's in the q= format), but as soon as I remove the q= part, it displays the data from the main (default, drupal-home) site.

I think I'm having the same problem as on this page: http://drupal.org/node/211131 . The difference is that I'm not using subdomains (will be in the future when the site is launched), but rather subfolders - not sure how to apply the suggested solution to my case.

---
Yuriy Babenko | Senior Developer
http://yuriybabenko.com

Sounds like an .htaccess/Apache issue then. There are docs in the handbook that explain them in great detail. For each multisite you are going to need to tell Apache to allow overriding in that directory, like so:

<Directory /var/www/htdocs/hosts/somesite.com>
     AllowOverride All
</Directory>

Adding that to your Apache httdp.conf file should fix the issue.

Now... the real question I should be asking is: is this a local server or web host? This solution will only work for a local server, but I know there are workarounds to make it work on web hosts. I may not be the one to ask though.

For the time being I'm working on a shared development server. I *could* ask the sys admin to add that to the Apache config, but I doubt I'll be able to do the same on the live production server. I'll see if I can dig up some of those workarounds, thanks for the tip!

---
Yuriy Babenko | Senior Developer
http://yuriybabenko.com

This is strange because normally
- "Run the clean URL test" simply checks whether they are already enabled by .htaccess
- "Enable" does not really enable them -- they are enabled and it simply uses them in the links.
Normally the .htaccess file is the only thing that matters (and the server configuration which allows it to work).

When you hover over "Run the clean URL test", does http://site.com/sales/admin/settings/clean-urls already contain "sales" and it disappears when you click on it? Or is "sales" already missing from the link? Is Drupal's .htaccess file unmodified?

Going to site.com/sales/?q=admin/settings/clean-urls shows the "sales" part of the site - correctly.
The enabled/disabled radio buttons are disabled, so I click the "Run the clean URL test" link which points to site.com/sales/admin/settings/clean-urls. It is at this point that it changes to the "home" part of the site, and the enabled/disabled radio buttons are activated. (This is still on site.com/sales/admin/settings/clean-urls).

The .htaccess is pretty much unmodified. The only thing that I changed was setting "RewriteBase /~kerunt/site" (the path to my site on the shared development server I'm using). Removing this breaks the clean URLs everywhere :(.

---
Yuriy Babenko | Senior Developer
http://yuriybabenko.com

OK, it seems that changing the RewriteBase from
RewriteBase /~kerunt/site
to
RewriteBase /~kerunt/site/sales

fixes the sales site, but, of course, breaks the main site

So, I need a way to have a different RewriteBase value for each of the sub sites. I guess having a different .htaccess for each sub-site would be the easiest way, but I can't seem to figure out how to get it to work?

Placing a different .htaccess in sites/sales-site-folder doesn't do anything :/...

---
Yuriy Babenko | Senior Developer
http://yuriybabenko.com

After spending (literally) two working days on this...

Here is the magic that did the trick:

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

rinse and repeat the same for other subfolder sites, and only THEN the main rewrite:

# Rewrite current-style URLs of the form 'index.php?q=x'.
# if file and directory do not exist, rewrite through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

It works, it works!

Thanks to everyone who helped out!

---
Yuriy Babenko | Senior Developer
http://yuriybabenko.com

Hi, I am having the same issue. I wonder if you can provide more details.

I created two virtual installations using symlinks, using the instructions here:

http://drupal.org/node/117658#comment-198789

So I know have site.com/1 and site.com/2

When I am logged in as admin in either site, running the Clean URL test gives me a 500 error, however.

the sites folder in my root looks like this:

all
default
site.com.1
site.com.2

I the last two folders -- site.com.1 and site.com.2 -- I have a single file, and that is settings.php

The main site and the two symlinked sites all share a common database, with different prefixes for the tables, of course.

Can you please explain where you put the modified .htaccess files you created to make clean urls work in the subdirectories?

Thanks so much.

Apparently yuriy put multiple blocks like this one in Drupal's .htaccess file, each one taking effect for one sub-site. The additional line is an additional condition: "... AND if the requested URL begins with this, then add this to the rewrite".

But I am not sure if the problem was the same as yours. Do your clean URLs work when you enter them manually in the browser? (with an unmodified .htaccess file)

Hi, thanks for writing and also for your excellent instructions. When I remove the "?q=" from the URL (with an unmodified .htaccess) the result is a 500 error. This is typical on my installation (1 and 1) where clean URL's do not work out of the box so to speak, and a change to .htaccess (rewritebase) is almost always necessary. This situation is different of course in that i am working with symlinks, and in that the folders I have created in /sites for each of the subdirectories I have symlinked only have settings.php files in them.

Any thoughts you might have would be greatly appreciated.

I can't give any specific advice without experimenting to see how that server setup behaves.

Have you considered creating subdomains for your sub-sites? If you make them accessible with http://subsite.example.com instead of http://example.com/subsite (also changing their Drupal "sites/subdirectory" names accordingly) then a RewriteBase / would be fine for all subsites because they won't have any additional base paths.

Hi, just to follow up, I did indeed make the switch, and clean URLs work as they should.

I now have:

site.com
abc.site.com
xyz.site.com

abc.site.com and xyz.site.com run off the site.com installation. very efficient and effective.

Now comes the next hurdle, and if you do not mind, I have some additional questions and would be grateful if you could advise me.

--At the moment, all three sites have independent tables (i.e., each has a unique prefix) in a single database.

--I intend to upload audio content to the mother site; this content will reside in site.com/files

--I have the audio module, getid3 module, and the relevant views modules activated independently (i.e., via their own DB tables on the shared database) for all three sites.

--I'd like abc.site.com and xyz.site.com users to be able to access the audio content I upload to site.com/files

--At the same time -- and this is where it might get tricky -- I'd like to use taxonomy access or some other form of content access control to determine what audio content is seen by the users on each site.

--For example, I am in site.com, and I upload song.mp3 via the audio node content type. I want the users at abc.site.com to be able to access this audio node, but I do not want it to be available to users at xyz.site.com.

I assume there are multiple ways to set this up. I know, for example, that some of the database tables will have to be shared (I am guessing node and node_revisions to start with, perhaps sequences and the audio tables as well).

Is there a single taxonomy access control table that is shared as well? Or does abc.site.com and xyz.site.com each have an independent taxonomy access control table of their own?

Any guidance the experts here can provide would be greatly appreciated. Many thanks for your time.

This is very complicated to be answered like this. Especially since I know next to nothing about the audio module. A few random comments:

If you share content you need to share users (athor's user IDs) and of course node_types. I am sure I am forgetting some.

To differentiate by category, you will need to share the taxonomy tables. Only with a shared term_node table (an all the rest) the author will be able to assign nodes to sites in one place.

I am not sure that access control is what you need. I mean, do you want the same view to be used on all sites and to come up empty if there are no permitted nodes? Or just to use different views, listing different categories?

You may find this one interesting. The author starts with a shared database and then differentiates: http://drupal.org/node/201673

Hi yuri,

could you possibly post an example of the .htaccess file that worked for you ? Do we now ignore the RewriteBase part ? In favour of you extra blocks ? I have a line about favicon which may be on a later ver aswell.

thanks

brunik

The rewrite rule changed a bit for Drupal 7. Here's the block that works for me:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} ^/subsite
RewriteRule ^ subsite/index.php [L]

Note: The leading slash in the last RewriteCond is required, as is the space after the ^ in the RewriteRule. (But a space on the RewriteCond line will break it. Oh, Apache...)

Crell,

To accomplish this with multisite sub-directories, did you place this in the .htaccess file, or inside an Apache .conf file?

Copied the above into my .htaccess, like so:

# Dept1
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteCond %{REQUEST_URI} ^/dept1
  RewriteRule ^ dept1/index.php [L]

No difference. Clean URLs don't work for sub-sites.

My particular site structure is:

/var/www/
  |
  ...core!...
  |
  sites
    |
    default
    |
    d7
    |
    d7.dept1
    |
    d7.dept2
    |
    ...

I also have symlinks in the root, for the subdirectories to work.

dept1 -> .
dept2 -> .
dept3 -> .

Additionally, I am using the default Apache config file.

Thanks for any help!

jtreinau

Though Crell's workaround didn't work in my instance, all I did to alter it was add a beginning "/" to my subsite: RewriteRule ^ /dept1/index.php [L]. See Crell's above, if that works for you, in contrast.

After that, just rinse and repeat, within the .htaccess root file, or within a <Directory> section of an Apache .conf file.

  # Dept1
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteCond %{REQUEST_URI} ^/dept1
  RewriteRule ^ /dept1/index.php [L]
  # Dept2
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteCond %{REQUEST_URI} ^/dept2
  RewriteRule ^ /dept2/index.php [L]
  # Dept3
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteCond %{REQUEST_URI} ^/dept3
  RewriteRule ^ /dept3/index.php [L]
  # Pass all requests not referring directly to files
  in the filesystem to
  # index.php. Clean URLs are handled
  in drupal_environment_initialize().
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ /index.php [L]

Thanks!

jtreinau

By the way jtrainau, the ordering of the Rewrite Conditions are critical. The default must be the last entry. Just making sure everyone knows. :)

Hello.

FYI

I find, and am willing to believe, that Drupal-centric hosting companies will already have this up and rolling, if they have their stuff together with multisite installs.

For example, if you go with Acquia you'll be set up, as we haven't had to lift a finger in this area.

Now, if you want to use this on a non-Drupal-tuned host (barring any lack of accesses), or on a personal dev (local *AMP instances), you should be free to run.

Not sure what a more concise Apache rewrite rule would be to have one rewrite to rule them all? Anyone an Apache master, who is willing to help?

Thanks!

jtreinau

Hi folks,

I like to report that it worked for me too. I had a similar situation: I run a development webserver, with multiple sites organized like

  • /var/www - Main site (quit empty)
  • /var/www/slangenboren - a subsite

Similar to others, CleanURLs worked fine for the main site, but not for the others. As someone mentioned here, I included the relevant Apache directive for both the main site and the subsite:

<Directory /var/www>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
<Directory /var/www/slangenboren>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

I restarted Apache through /etc/init.d/apache2 restart , and it just worked!

Thanks a lot & regards,

Jeroen Strompf

http://www.DeVliegendeBrigade.nl - Webshops
http://www.DeVliegendeBrigade.nl/wiki - Our knowledge base
http://www.carbonbrushes-online.com - For automotive, power tools and household appliances

I was having the same problem, and when I tried your suggestion above, was still having the problem. Changing the "RewriteBase /" to "RewriteBase /subdir/" in the Apache Directory directive for the subsite fixed it for me.

Thanks!

Pat

After spending (like yuriy.babenko) about two days for configuring clean URLs I decide to debug it. This can be done with Apache RewriteLog Directive and RewriteLogLevel Directive:

RewriteLog "/home/lapurD/apache_rewrite.log"
RewriteLogLevel 4

And after some hours of watching what is happening I achieve this working configuration:
symbolic link "example2.com" in example.com root directory which points to example.com root directory:
ln -s /www/example.com/ /www/example.com/example2.com
and following lines in example.com configuration file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(example2\.com|)(.*)$ $1/index.php?q=$2 [L,QSA]

where my default site is example.com and second one example2.com is into subdirectory sites/example.com.example2.com/, and the URL to access the second site is http://example.com/example2.com/

Using Drupal 7 in a shared hosting environment where I can host multiple domains.

I want to set-up several sites like the following:

www.example.com =>> main domain

add-on domains and subsites:
www.example.com/subsite
www.example2.com
www.example2.com/subsite
www.example3.com
www.example3.com/subsite

I have no trouble installing the main domain and the add-on domains(example2.com & example3.com).
I can't figure out how to install the add-on domain subsites in their subdirectories.

Hi Superkuton

I am using drupal 7 and want to create a multisite like www.example.com/subsite .
From your postings I learnt that you had no trouble installing the main domain and the add-on domains.Could you please provide the step by step instructions.

one clarification : I am accessing my dev server with a some dummy name then how do I test the multisite with same domain using sub dir.

Please give the steps you have followed.

Thanks in advance
Revathi

Hi Akshita

To install Drupal for the main domain and add-on domains:
for illustration purposes:
main domain = example.com
add-on domain, = example2.com, example3.com

I use cpanel in a shared hosting environment.
I have the main domain pointing to a subdirectory (public_html/drupal-7.8)
When I add the other domains (example2.com & example3.com), I point them to the same subdirectory (public_html/drupal-7.8)

Then in the public_html/drupal-7.8/sites subdirectory,
I create folders for the added domains (example2.com & example3.com),
copy the default.settings.php and settings.php files into each of the folders,
create the database and the database user for each of the add-on domains
then I do the normal installation process.

there's nothing new to it.
my problem was in installing sites in subdirectories like

example.com/sales
example2.com/sales
example2.com/hr
example3.com/sales
example3.com/hr

I think, I don't seem to understand the .htaccess configurations
and can't get the working of symlinks for the main and add-on domains.

How do you configure the subdirectories, .htaccess and symlinks?