• Welcome to LiuJason's Blog!

WordPress改写所有http链接为https协议|全站SSL

Web项目 Jason 3 years ago (2020-11-01) 516 Views 0 Comments QR code of this page
文章目录[隐藏]

前言

自己的多个网站都使用了百度的CDN,一级域名下只能设置一种回源模式:要么全程ssl要么半程ssl。由于部分服务的源站没办法使用ssl加密,所以只能选择半程。
但是半程意味着http回源,导致WordPress给出的所有链接均为http,于是报错....

解决方案

后台设置里面,依次打开【外观】》【主题编辑器】》【模板函数 (functions.php)】
在末尾添加如下代码:

/** 替换链接为https **/
function rewrite_to_https($content){
    if( is_ssl() ){
        $content = str_replace('http://', 'https://', $content);
    }
    return $content;
}
add_filter('the_content', 'rewrite_to_https');

保存即可。


This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/1077.html
Like (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址