1.20.x bootstrap.inc find_conf_path($http_host, $script_name, $require_settings = TRUE)

Finds the appropriate configuration directory for a given host and path.

This function is the heart of Backdrop's multisite functionality, determining which directory should be used based on the hostname. If not using multisite, the path returned will be a single period (indicating the current directory).

Parameters

$http_host: The hostname and optional port number, e.g. "www.example.com" or "www.example.com:8080".

$script_name: The part of the url following the hostname, including the leading slash.

Return value

The relative path of the matching configuration directory.:

See also

conf_path()

File

includes/bootstrap.inc, line 603
Functions that need to be loaded on every Backdrop request.

Code

function find_conf_path($http_host, $script_name, $require_settings = TRUE) {
  $conf = '.';
  $sites = array();

  // This will overwrite $sites with any multisite mappings.
  if (file_exists(BACKDROP_ROOT . '/sites/sites.php')) {
    include BACKDROP_ROOT . '/sites/sites.php';
  }

  if ($sites) {
    $uri = explode('/', $script_name);
    $uri[0] = ($uri[0] == '.') ? '' : $uri[0];
    $server = explode('.', implode('.', array_reverse(explode(':', rtrim($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 (isset($sites[$dir]) && file_exists(BACKDROP_ROOT . '/sites/' . $sites[$dir])) {
          $dir = $sites[$dir];
        }
        if (file_exists(BACKDROP_ROOT . '/sites/' . $dir . '/settings.php') || (!$require_settings && file_exists(BACKDROP_ROOT . '/sites/' . $dir))) {
          $conf = './sites/' . $dir;
          return $conf;
        }
      }
    }
  }

  return $conf;
}