diff --git includes/bootstrap.inc includes/bootstrap.inc index 66b1135..e4bdffd 100644 --- includes/bootstrap.inc +++ includes/bootstrap.inc @@ -306,6 +306,30 @@ function timer_stop($name) { * * 13. $confdir/default * + * If a file named sites.php is present in the $confdir, it will be loaded + * prior to scanning for directories. It should define an associative array + * named $sites, which maps domains to directories. It should be in the form + * of: + * + * $sites = array( + * 'The url to alias' => 'A directory within the sites directory' + * ); + * + * For example: + * + * $sites = array( + * 'devexample.com' => 'example.com', + * 'localhost.example' => 'example.com', + * ); + * + * The above array will cause Drupal to look for a directory named + * "example.com" in the sites directory whenever a request comes from + * "example.com", "devexample.com", or "localhost/example". That is useful + * on development servers, where the domain name may not be the same as the + * domain of the live server. Since Drupal stores file paths into the database + * (files, system table, etc.) this will ensure the paths are correct while + * accessed on development servers. + * * @param $require_settings * Only configuration directories with an existing settings.php file * will be recognized. Defaults to TRUE. During initial installation, @@ -325,12 +349,22 @@ function conf_path($require_settings = TRUE, $reset = FALSE) { } $confdir = 'sites'; + + $sites = array(); + if (file_exists($confdir . '/sites.php')) { + // This will overwrite $sites with the desired mappings. + include($confdir . '/sites.php'); + } + $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']); $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.'))))); 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") || (!$require_settings && file_exists("$confdir/$dir"))) { + if (isset($sites[$dir]) && file_exists($confdir . '/' . $sites[$dir])) { + $dir = $sites[$dir]; + } + if (file_exists($confdir . '/' . $dir . '/settings.php') || (!$require_settings && file_exists($confdir . '/' . $dir))) { $conf = "$confdir/$dir"; return $conf; } diff --git sites/example.sites.php sites/example.sites.php new file mode 100644 index 0000000..48cd41f --- /dev/null +++ sites/example.sites.php @@ -0,0 +1,46 @@ + 'example.com', + * 'localhost.example' => 'example.com', + * ); + * + * The above array will cause Drupal to look for a directory named + * "example.com" in the sites directory whenever a request comes from + * "example.com", "devexample.com", or "localhost/example". That is useful + * on development servers, where the domain name may not be the same as the + * domain of the live server. Since Drupal stores file paths into the database + * (files, system table, etc.) this will ensure the paths are correct while + * accessed on development servers. + * + * To use this file, copy and rename it such that its path plus filename is + * 'sites/sites.php'. If you don't need to use multi-site directory aliasing, + * then you can safely ignore this file, and Drupal will ignore it too. + */ + +/** + * Multi-site directory aliasing: + * + * Edit the lines below to define directory aliases. Remove the leading hash + * signs to enable. + */ +#$sites = array( +# 'devexample.com' => 'example.com', +# 'localhost.example' => 'example.com', +#);