From e8291926cca71a43c85b89d4f446082cc24c8307 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 5 Jan 2016 23:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9F=9F=E5=90=8D=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=A3=80=E6=B5=8B=20=E5=8E=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 -- library/think/Route.php | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/convention.php b/convention.php index 7e0b2222..325d5653 100644 --- a/convention.php +++ b/convention.php @@ -87,8 +87,6 @@ return [ '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 f380d1e8..70adef25 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -124,6 +124,12 @@ class Route } } + // 对路由进行绑定 + public static function bind($type, $bind) + { + self::$bind[$type] = $bind; + } + // 路由分组 public static function group($name, $routes = [], $type = '*', $option = [], $pattern = []) { @@ -163,8 +169,6 @@ class Route // 检测子域名部署 public static function checkDomain() { - // 检测是否开启子域名支持 - if(!Config::get('url_domain_deploy')) return; // 域名规则 $rules = self::$domain; // 开启子域名部署 支持二级和三级域名 @@ -173,12 +177,14 @@ class Route // 完整域名或者IP配置 $rule = $rules[$_SERVER['HTTP_HOST']]; } else { - // 检测是否配置域名根 - $root = Config::get('url_domain_root'); - if(empty($root)) return; + $rootDomain = Config::get('url_domain_root'); + if ($rootDomain) { + // 配置域名根 com.cn net.cn 之类的域名需要配置 + $domain = explode('.', rtrim(stristr($_SERVER['HTTP_HOST'], $rootDomain, true), '.')); + } else { + $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2); + } // 子域名配置 - $domain = rtrim(preg_replace('/'.preg_quote($root).'$/', '', $_SERVER['HTTP_HOST']), '.'); - $domain = explode('.', $domain); if (!empty($domain)) { $subDomain = implode('.', $domain); $domain2 = array_pop($domain); // 二级域名 @@ -246,10 +252,12 @@ class Route public static function check($url, $depr = '/') { // 检测域名部署 - self::checkDomain(); + if (Config::get('url_domain_deploy')) { + self::checkDomain(); + } if (isset(self::$bind['module'])) { - // 如果有模块/控制器绑定 + // 如果有模块/控制器绑定 针对路由到 模块/控制器 有效 $url = implode('/', self::$bind['module']) . '/' . $url; }