马上就加载好了...

如何让WordPress站内链接都支持https?

by on Jan 08 , 2018 , under 学术 , 622 views , Leave a Comment

自从去年发布的《本站全面启用https安全连接》后,不少网友都来问如何让WordPress站内链接支持https?今天就把几个简单的方法告诉大家。

注意,以下方法的前提是你的网站已经可以使用https访问!目前新版wordpress已经给大家免费的ssl证书了,所以https访问已经不难。

第一步:更换站点链接

方法1:可以直接登陆后台,通过“设置”中“常规”里面把“WordPress地址(URL)”、“站点地址(URL)”两个地址的http修改为https并保存。

方法2:通过修改wp-config.php文件,直接在文件末尾加入以下两行代码:

define(‘FORCE_SSL_LOGIN’, true);
define(‘FORCE_SSL_ADMIN’, true);

第二步:替换内容或文件链接

方法1:编辑当前主题下的 functions.php 文件,加入以下代码,以本站替换图片链接为例:

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

方法2:直接运行SQL语句批量替换内容,记得备份数据库,比如本站:

update wp_posts set post_content = replace(post_content, ‘http://wjd.name’,’http s://wjd.name’);   (空格和符号请自行替换)

第三步:强制使用https

方法1:配置.htaccess文件,使网站301重定向到HTTPS:

#网站定制化开启 HTTPS 的301重定向
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_USER_AGENT} !MSIE/[1-8]\. [NC]
RewriteCond %{HTTP_HOST} wjd.name
RewriteRule ^.*$ http://wjd.name%{REQUEST_URI} [L,R=301]

方法2:在 nginx 配置中添加如下 server block

server {
listen 80;
server_name your_domain.com;
return http://wjd.name$request_uri;
}

 

沙发竟然还没被抢!


赶快说点什么吧! ^_^