conf_path is broken in setups with multiple sites per domain, and URL aliases in Apache.
$_SERVER['REQUEST_URI'] returns the URL in the browser, eg. somesite.com/somefolder
$_SERVER['SCRIPT_NAME'] returns index.php whenever 404 is used!
My configuration has the following setup in vhosts.conf
Alias /site1 /var/www/drupal6
Alias /site2 /var/www/drupal6
This means that i can have two different sites with the same codebase in different "folders" on the server. This does the same as adding subdomains, just that i have multiple sites within one domain. (This should be a supported setup by drupal)
Here's my settings folder:
tbartist.com.site1/settings.php
tbartist.com.site2/settings.php
default/settings.php
Request to: http://tbarstist.com/site1:
$_SERVER['SCRIPT_NAME'] = /site1/index.php
$_SERVER['REQUEST_URI'] = /site1/
Note: /site1 is a valid path due to apache Alias in /site1.
Both ways ok here!
Request to: http://tbartist.com/site1/admin:
Server looks in /var/www/drupal6 for admin, and 404's
The error message calls /var/www/drupal6/index.php
Now let's look at what is returned by the server variables:
$_SERVER['SCRIPT_NAME'] = /index.php (WRONG!) results in sites/default/settings.php to be returned.
$_SERVER['REQUEST_URI'] = /site1/admin/ (CORRECT!)
Here we see that due to Apache's 404 redirect, SCRIPT_NAME returns a wrong path to use in conf_path.
Correcting SCRIPT_NAME to REQUEST_URI corrects the problem.
I have attached a one-liner patch.
Please follow up.
Regards,
Johan.
Comment | File | Size | Author |
---|---|---|---|
bootstrap.inc-fix-conf_path.patch | 571 bytes | johandc | |
Comments
Comment #1
Gábor HojtsyWell, the REQUEST_URI is user provided data so it should not be used as-is. That's why we migrated to using SCRIPT_NAME. Why are you using 404s? The url rewrite should not go through any 404s.
Comment #2
johandc CreditAttribution: johandc commentedI used to create nice urls by letting the browser redirect 404 errors to index.php, and let index.php parse the REQUEST_URI and generate the page accordingly. Now i remember that Drupal uses mod_rewrite to do the redirect to index.php, and therefore does not 404. I'm sorry to have confused things here.
Either way, the resulting script executing the page is /index.php.
And in the case my url is aliased to be somesite.com/somesite1/admin, SCRIPT_NAME does not return the desired /somesite1/index.php like it should, but rather /index.php, which is makes conf_path select the wrong config.
If we can't use REQUEST_URI, how can we then solve the problem?
The current durpal 6.x will not work with different configs per sub-directory due to this fact.
Perhaps some of the issue lies within the fact that i have Aliased my subfolder to the drupal code base, like this:
Alias /site1 /var/www/drupal6
How do other people make different sites per. sub-directory?
Is it possible at all?
Comment #3
chx CreditAttribution: chx commentedUnless somebody confirms real breakage, this sounds like an Apache configuration issue.
Comment #4
catchComment #5
ricabrantes CreditAttribution: ricabrantes commentedNo activity, Close..
Comment #6
progga CreditAttribution: progga commentedWe had a similar issue with a D5 site. We had to turn off clean-urls to get it working. Here is why:
Because we had to rely on mod_alias to get subdir-based multisites, the rewrite rules were taking precedance over the Alias rule. This is mentioned in the mod_alias docs at http://httpd.apache.org/docs/2.2/mod/mod_alias.html (see the "Order of Processing" section). Turning off clean-urls mean the rewrite rules from .htaccess will not take affect and let mod_alias handle the urls. This results in $_SERVER['SCRIPT_NAME'] containing the subdir name in its value.
So we now have a working subdir-based multisite with ugly-urls :-(
Comment #7
lostchord CreditAttribution: lostchord commentedThis is the documentation supplied in default.settings.php:
This seems to be completely at variance with the current implementation (6.15 in my case) where it would seem it will NEVER work as advertised.
I came to the same conclusion as the original poster after inserting my own debug statements into conf_path following several hours of head banging and messing with sym links.
The documentation clearly shows thet the user input is used as the basis for the search but the implementation ignores the user input by design.
So, are sub-directory multi-sites actually supported? Can we have some definitive answer on that?
cheers.
Comment #8
Damien Tournoud CreditAttribution: Damien Tournoud commentedWorks perfectly for me, with the following in my
sandbox.lab
vhost configuration:The following conf paths are tested:
Apache 2.2.12, PHP 5.2.10, Drupal 6.16
Comment #9
lostchord CreditAttribution: lostchord commentedSo your supplied URL in the first case is:
http://sandbox.lab/test-site
I can get multi-site sub-domains working with no trouble whatsoever, it's the sub-directory config that requires URLs like the one above that is the problem.
Updated:
Early days yet, but just tried the Alias statement in the VirtualHost definition and it seems to be making a big difference.
Update 2:
That does indeed make everything work.
Many thanks :-)
Comment #10
cwarden@xerus.org CreditAttribution: cwarden@xerus.org commentedI'm also experiencing this bug, in which $_SERVER['SCRIPT_NAME'] contains /index.php, preventing sub-directory multi-site from working. For example, if I request http://drupal.example.com/subdir/, $_SERVER is populated with:
Comment #12
GaëlGHere's our workaround when Alias and Rewrite don't work well together for sites like:
http://same.domain/site-a/
http://same.domain/site-b/