正文
Emlog5.31默认不支持https,需要手动修改系统文件以支持,在进行修改之前,请先确定服务器已正确配置https,并且备份所有文件,防止出现问题。
1. /include/lib/option.php
请将以下内容粘贴到 get function 的 default 判断分支之前 (在Emlog 5.3.1下是第43行)。
case 'blogurl': return realUrl(); break;
2. /include/lib/function.base.php
请将以下内容粘贴到文件的末尾
/** * 获取当前访问的base url */ function realUrl() { static $real_url = NULL; if ($real_url !== NULL) { return $real_url; } $emlog_path = EMLOG_ROOT . DIRECTORY_SEPARATOR; $script_path = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME); $script_path = str_replace('\\', '/', $script_path); $path_element = explode('/', $script_path); $this_match = ''; $best_match = ''; $current_deep = 0; $max_deep = count($path_element); while($current_deep < $max_deep) { $this_match = $this_match . $path_element[$current_deep] . DIRECTORY_SEPARATOR; if (substr($emlog_path, strlen($this_match) * (-1)) === $this_match) { $best_match = $this_match; } $current_deep++; } $best_match = str_replace(DIRECTORY_SEPARATOR, '/', $best_match); $real_url = $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://'; $real_url .= $_SERVER["SERVER_NAME"]; $real_url .= in_array($_SERVER['SERVER_PORT'], array(80, 443)) ? '' : ':' . $_SERVER['SERVER_PORT']; $real_url .= $best_match; return $real_url; }
3. /init.php
请用以下代码覆盖同名的define (在Emlog 5.3.1下是第39行)。
define('DYNAMIC_BLOGURL', Option::get("blogurl"));
好了,修改完成,试试用https访问吧,然后可以配置http强制301跳转至https,利于SEO优化。
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《Emlog全站开启https》
文章链接: https://www.sgtms.com/other/67.html
本站资源仅供个人学习交流,转载或者引用本文内容请注明来源及作者,不允许用于商业用途。
文章名称:《Emlog全站开启https》
文章链接: https://www.sgtms.com/other/67.html
本站资源仅供个人学习交流,转载或者引用本文内容请注明来源及作者,不允许用于商业用途。
网友评论抢沙发