To get around having to modify web server configuration files in order to get multi-site capability, i modified one of the functions in bootstrap.inc. By adding an appropriate folder in the sites folder, one can achieve multisite feature without having to go to web server configurations file, which most Drupal admin users dont have access to.
The modified function simply grab the first element in $_GET['q'] and use that to find appropriate settings.php. Once it find the right settings.php, it removes the first element in GET query and replace it with the remaining query. A simple sleigh of hand
If anyone want to use this, simply copy the function below and replace the one in bootstrap.inc
The only concern I have is the security implication that the function below may have. Does anyone here know what security issues I should be worried about?
function conf_init() {
static $conf = '';
if ($conf) {
return $conf;
}
$confdir = 'sites';
$uri = explode('/', $_SERVER['PHP_SELF']);
$server = explode('.', rtrim($_SERVER['HTTP_HOST'], '.'));
//put GET query into array
$path = explode('/', strtolower($_GET['q']));
//grab first element in GET query
//use it to find the right folder in sites directory
$member =$path[0];
//not empty, insert it into uri array
if(isset($member) && $member != ''){
//make copy of exploded uri
$copy_uri = array();
$copy_uri = $uri;
//find length of uri
$width = count($uri) - 1;
//overwrite the last element of uri-copy
$copy_uri[$width] = $member;
//now add the last element of exploded uri to uri-copy
array_push($copy_uri, $uri[$width]);
//reset exploded uri with the uri-copy
$uri = $copy_uri;
}
for ($i = count($uri) - 1; $i > 0; $i--) {
for ($j = count($server); $j > 0; $j--) {
$dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
if (file_exists("$confdir/$dir/settings.php")) {
//if first element is in dir then remove member from GET query
if(strstr($dir, $member)){
/*
* Sleigh of hand happening here
* Lame code to remove first element in GET query
* reset GET query with new path
*/
$path = array_reverse($path,true);
array_pop($path);
$path = array_reverse($path,true);
$_GET['q'] = implode('/',$path);
}
$conf = "$confdir/$dir";
return $conf;
}
}
}
$conf = "$confdir/default";
return $conf;
}