Duke Yin's Technology database

全站改https的方法

如今个人ssl证书已经很便宜,很多商家甚至提供免费的ssl证书,如何让我们的网站获得全站ssl证书?

网站配置文件中开放443端口

填写获得的ssl密钥文件地址

WordPress设置中修改主站地址为https

在数据库中替换所有图片以及其他附件地址为https

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.domain.com/wp-content/uploads','https://www.domain.com/wp-content/uploads');

如果你不太会使用mysql命令,还可以在主题的functions.php中添加如下代码以达到附件地址替换为https

/* 替换图片链接为 https */
function my_content_manipulator($content){
if( is_ssl() ){
$content = str_replace('http://www.domain.com/wp-content/uploads', 'https://www.domain.com/wp-content/uploads', $content);
}
return $content;
}
add_filter('the_content', 'my_content_manipulator');

强制后台使用https
在wp-cofig 文件中加入如下条目

/* 强制后台和登录使用 SSL */
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);

由于https要求全部外链文件都必须是https,所有如果之前主题引用了http的资源,比如logo图片地址,jQ文件或者其他js,记得要替换引用的地址为https,尽量放本地加载。

如此以来,就可以以https正常访问了。

# #

发布评论

评论

标注 * 的为必填项。