91版本库 发表于 2019-10-7 19:17:54

dz 强制HTTPS http跳转至 https的解决方案

打开 source/class/class_core.php 文件,找到 set_exception_handler(array('core', 'handleException'));

后面加入:


if($_SERVER['SERVER_PORT'] != '443' && $_SERVER['PHP_SELF'] != '/api/uc.php') {         if(!preg_match("/(Qtvcd|Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla)/i", $_SERVER['HTTP_USER_AGENT'])) {               header('HTTP/1.1 301 Moved Permanently');               header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);               exit;         } elseif(preg_match("/(Baidu|Google)/i", $_SERVER['HTTP_USER_AGENT'])) {               header('HTTP/1.1 403 Forbidden');               exit;         } }



说明:当访问端口不为443(即https)时,如果不是搜索引擎则跳转到https页面,否则如果是百度或Google蜘蛛(这两个搜索引擎已支持收录https)则返回403禁止访问,避免重复收录 http 和 https 或优先收录了 http ,其它搜索引擎未定义,正常返回 http 页面(其它搜索引擎可能不支持收录 https ,因此开放 http 给他们)。
以上代码中“Qtvcd”可以任意修改,管理员使用以下UA可以不跳转到https,便于对http版进行调测:
Mozilla/5.0 (compatible; Zidingyi/2015; +http://www.xxx.com)


页: [1]
查看完整版本: dz 强制HTTPS http跳转至 https的解决方案