Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The university where I work is planning to offer Drupal hosting to staff/faculty who want a Drupal site. We've set up Drupal multisite with clean urls and it's mostly working except for some weird redirects. If you have two sites where one is a substring of the other then you'll randomly be redirected to the other site. I tracked the problem to how mod_rewrite does path matching, so with a config file like this:

RewriteCond %{REQUEST_URI} ^/drupal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /drupal/index.php?q=$1 [last,qsappend]

RewriteCond %{REQUEST_URI} ^/drupaltest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /drupaltest/index.php?q=$1 [last,qsappend]

/drupaltest will match the /drupal line and all of the links on the /drupaltest page will be rewritten to point to /drupal.

If you put the end of string character ($) at the end of each rewrite condition then it will always match on the correct site and the links will always be rewritten correctly. That breaks down as soon as a user logs in though because the query string is appended to the url so just the base url will no longer match.

You can also fix the problem by ordering the sites in the config file so that the smallest substring will always be last. I suggested storing all of the sites in a table and then querying, sorting, and rewriting the config file every time a Drupal site is requested so that we could guarantee the order. The system administrator thought that was kludgy and didn't address the root problem.

Disabling clean urls should also fix the problem but the users really want them so I'd prefer to keep them if possible. I think we could also fix it by using an .htaccess file in each site to handle the clean url rewriting but that also seems suboptimal since it will generate a higher load on the server and the server is intended to host the majority of the university's external facing web content.

Is there some magic I can do with mod_rewrite to get it to work? Would another solution be better? Am I doing something the wrong way to begin with?

share|improve this question
    
What multisite setup are you running? Are you running it all off of one d/b are you using domain access or are you running prefix off one install? –  lilott8 Nov 9 '09 at 19:10
    
There's one central drupal codebase but each child install has its own db. –  moexu Nov 10 '09 at 18:31
    
Not really an answer, but just a comment to suggest you look into switching http server to nginx. You might have noticed that apache+drupal=balckhole of memory. With nginx you can reduce memory consumption to a fraction of apache. There is a group specifically for this: groups.drupal.org/nginx. There you can find also examples on how to set up clean URL. D7 will be out soon and - while being surely more powerful and user-friendly - I can anticipate it's going to be even heavier than D6. –  mac Nov 14 '09 at 23:50
1  
I can't help feeling it'd all run much smoother on subdomains. You'd also then be able to use Aegir to manage this setup which would make everything really nice and easy. If you're set upon using separate folders then go with separate Drupal installs rather than multisite - it'll make upgrading so much easier. –  kaerast Jun 25 '10 at 16:12
add comment

1 Answer

This seems to work:

RewriteCond %{REQUEST_URI}/ ^/drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /drupal/index.php?q=$1 [last,qsappend]

RewriteCond %{REQUEST_URI}/ ^/drupaltest/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /drupaltest/index.php?q=$1 [last,qsappend]

Thanks to everyone who looked at it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.