diff --git a/convention.php b/convention.php index 4203e918..7e0b2222 100644 --- a/convention.php +++ b/convention.php @@ -85,6 +85,8 @@ return [ 'url_module_map' => [], // 域名部署 'url_domain_deploy' => false, + // 域名根,如.thinkphp.cn + 'url_domain_root' => '', // 域名部署规则 'url_domain_rules' => [], diff --git a/library/think/Route.php b/library/think/Route.php index 31939f11..f7d68b7b 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -163,6 +163,11 @@ class Route // 检测子域名部署 public static function checkDomain() { + // 检测是否开启子域名支持 + if(!Config::get('url_domain_deploy')) return; + $root = Config::get('url_domain_root'); + // 检测是否配置域名根 + if(empty($root)) return; $rules = self::$domain; // 开启子域名部署 支持二级和三级域名 if (!empty($rules)) { @@ -171,7 +176,8 @@ class Route $rule = $rules[$_SERVER['HTTP_HOST']]; } else { // 子域名配置 - $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2); + $domain = rtrim(rtrim($_SERVER['HTTP_HOST'], $root), '.'); + $domain = explode('.', $domain); if (!empty($domain)) { $subDomain = implode('.', $domain); $domain2 = array_pop($domain); // 二级域名