WordPress使用Cloudflare后式样错乱的解决办法

最近博客增加了一层cloudflare的保护,但是不知为何同样都是启用了HTTPS,放在我的服务器上仅仅弹出警告,而经过cloudflare后提示错误,也不能正常显示页面了。

尝试了自己替换文本文件,结果失败了。访问网页提示错误。

使用插件

尝试使用 SSL Insecure Content Fixer 或 Really Simple SSL 插件。但是没有什么用。

批量替换主题中的http为https

写了一个脚本用于批量替换:

# 设置要替换的目录路径
dir = "D:\Users\AD_SVN01\Downloads\www.antior.cn_20230313_203534"

# 设置要替换的文本search = "http://"
replace = "https://"

# 遍历目录内的文件
Get-ChildItemdir -Recurse | ForEach-Object {
    # 判断是否是文本文件
    if (_.Extension -match "\.txt|\.csv|\.xml|\.html|\.css|\.js|\.php") {
        Write-Host "正在处理文件(_.FullName) ..."
        # 读取文件内容content = Get-Content _.FullName
        # 替换文本newContent = content -replacesearch, replace
        # 将替换后的文本写回文件
        Set-Content_.FullName newContent
        Write-Host "已替换文件($_.FullName) 中的文本。"
    }
}

Write-Host "所有符合条件的文件都已处理完毕。"

但是可能不小心替换了别的内容,总之报错。

Cloudflare内设置

在Cloudflare内设置 Automatic HTTPS Rewrites

在此设置
但是一会儿就有重定向错误。

需要同时在wp-config.php中添加如下内容:

// www.runoon.com/wordpress/wordpress-https-ssl-upgrade.html
$_SERVER['HTTPS'] = 'on';
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);

ref:
1. 解决混合内容错误

版权声明:
作者:antior
链接:https://www.antior.cn/html/20230313_288.html
来源:Antior的个人网站
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>