zoukankan      html  css  js  c++  java
  • Drupal配置文件settings.php搜索规则

    Drupal的配置文件搜索是通过bootstrap.inc的conf_path()函数实现的:

    function conf_path($require_settings = TRUE, $reset = FALSE) {
      $conf = &drupal_static(__FUNCTION__, '');
    
      if ($conf && !$reset) {
        return $conf;
      }
    
      $confdir = 'sites';
    
      $sites = array();
      if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/sites.php')) {
        // This will overwrite $sites with the desired mappings.
        include(DRUPAL_ROOT . '/' . $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 (isset($sites[$dir]) && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $sites[$dir])) {
            $dir = $sites[$dir];
          }
          if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir . '/settings.php') || (!$require_settings && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir))) {
            $conf = "$confdir/$dir";
            return $conf;
          }
        }
      }
      $conf = "$confdir/default";
      return $conf;
    }

    例如,对网址http://www.drupal.org:8080/mysite/test/的访问,Drupal会安装下面的顺序搜索配置文件:

    sites/8080.www.drupal.org.mysite.test
    sites/www.drupal.org.mysite.test
    sites/drupal.org.mysite.test
    sites/org.mysite.test
    
    sites/8080.www.drupal.org.mysite
    sites/www.drupal.org.mysite
    sites/drupal.org.mysite
    sites/org.mysite
    
    sites/8080.www.drupal.org
    sites/www.drupal.org
    sites/drupal.org
    sites/org
    
    sites/default

    sites/sites.php可以为站点设置别名。例如可以把访问http://www.drupal.org:8080/mysite/test/的配置文件重定向到example.com/settings.php:

    $sites['8080.www.drupal.org.mysite.test'] = 'example.com';

    参考:

    Multisite - Sharing the same code base

  • 相关阅读:
    hdu 5646 DZY Loves Partition
    bzoj 1001 狼抓兔子 平面图最小割
    poj 1815 Friendship 最小割 拆点 输出字典序
    spoj 1693 Coconuts 最小割 二者取其一式
    hdu 5643 King's Game 约瑟夫环变形
    约瑟夫环问题
    hdu 5642 King's Order
    CodeForces 631C Report
    1039: C语言程序设计教程(第三版)课后习题9.4
    1043: C语言程序设计教程(第三版)课后习题10.1
  • 原文地址:https://www.cnblogs.com/eastson/p/3351526.html
Copyright © 2011-2022 走看看