TSYBLOG.COM

WordPress部署SSL,全站开启https访问

一、开启https访问域名301重定向

借助.htaccess 文件实现 301 重定向,编辑网站根目录的.htaccess,加入以下代码:

RewriteCond %{HTTPS} !on [NC] RewriteRule (.*) http://xxx.cn%{REQUEST_URI} [R=301,NC,L]

或者

#网站定制化开启 HTTPS 的 301 重定向 RewriteCond %{SERVER_PORT} !^443$ RewriteCond %{HTTP_USER_AGENT} !MSIE/[1-8]\. [NC] RewriteCond %{HTTP_HOST} www.tuhongwei.com RewriteRule ^.*$ https:/域名%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# BEGIN WordPress
# 在`BEGIN WordPress`与`END WordPress`之间的指令(行)是
# 动态生成的,只应被WordPress过滤器修改。
# 任何对标记之间的指令的修改都会被覆盖。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

 # END WordPress 

二、登录和后台强制开启 SSL

修改 WP-config.php 文件,直接在文件末尾加入以下代码:

/* 强制后台和登录使用 SSL */
$_SERVER['HTTPS'] = 'on';
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);

三、让站内链接支持 SSL

上传到空间的附件都被 WordPress 标记为了绝对链接,一般需要修改数据库,但这种方法比较危险,因此推荐另一种方法
代码法,编辑当前主题下的 function.php 文件,加入以下代码:

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

喜欢本文?
文章阅读
常见问题
免费下载或者VIP会员专享资源能否直接商用?
提示下载完成但无法解压?
投稿及掉连解决方法:

本站均测试后上架,保证所提供下载的资源的准确性、安全性和完整性。

如有链接无法下载、失效或广告,下方评论区留言,或联系客服处理,看到处理!

如果您也有好的资源或教程,您可以投稿发布,所得成本报酬归发布方所有!

发表评论