惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
The GitHub Blog
The GitHub Blog
小众软件
小众软件
美团技术团队
博客园 - 司徒正美
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
J
Java Code Geeks
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
V
V2EX
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog

WrodPress – Ed_'s Blog

暂无文章

[记录]WordPress全站开启SSL访问 – yywr's Blog
yywr · 2019-03-03 · via WrodPress – Ed_'s Blog

环境背景:

  • WordPress 5.0
  • 使用DirectAdmin面板的虚拟主机

开启步骤

  1. DA面板SSL管理中一键申请Let’s Encrypt(需虚拟主机支持)
  2. DA面板 [更改设置]中[private_html安装 yywr.net – (SSL必须已经启动)]选项为:" 使用一个符号链接从private_html到public_html – 允许同样的数据在http和https中",这个选项确保HTTP和HTTPS使用同一个目录的内容.
  3. WP后台常规设置 WordPress地址和站点地址为https://www.yywr.net
  4. 开启后台SSL,在网站根目录下添加下面代码.(WP 5.0测试不添加也OK,应该是WordPress现在的版本自身支持)
/* 强制后台和登录使用 SSL*/
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
  1. 更新站内图片链接,将站内绝对地址更新为相对地址,在当前主题根目录下的functions.php添加下面代码
//WordPress SSL
add_filter('get_header', 'fanly_ssl');function fanly_ssl(){
if( is_ssl() ){
function fanly_ssl_main ($content){
$siteurl = get_option('siteurl');
$upload_dir = wp_upload_dir();
$content = str_replace( 'http:'.strstr($siteurl, '//'), strstr($siteurl, '//'), $content);
$content = str_replace( 'http:'.strstr($upload_dir['baseurl'], '//'), strstr($upload_dir['baseurl'], '//'), $content);
return $content;
}
ob_start("fanly_ssl_main");
}}
  1. 添加301跳转,在网站根目录下的.htaccess添加下面代码
#开启 HTTPS 的301重定向
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

参考资料:

  • 测试安全性:https://www.ssllabs.com/ssltest/
  • https://kzyblog.com/3760.html
  • https://zhangzifan.com/wordpress-ssl-link.html
  • https://www.wpdaxue.com/wordpress-forces-http-redirection-to-https-under-apache-host.html