在互联网火热的今天,安全问题显得越来越重要,为了用户信息安全,很多热门网站都启用了https

有小伙伴就问:我启用了https,为什么访问的时候显示的还是http呢?

其实,有时候并不是因为我们ssl证书配置的不对,而是因为我们没有做https强制跳转

下面介绍下wordpress下怎么设置https强制跳转:
<div class="cnblogs_Highlighter sh-gutter">
<div>
<div id="highlighter_878006" class="syntaxhighlighter php">

<div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="line number4 index3 alt1">4</div> <div class="line number5 index4 alt2">5</div> <div class="line number6 index5 alt1">6</div> <div class="line number7 index6 alt2">7</div> <div class="line number8 index7 alt1">8</div> <div class="container"> <div class="line number1 index0 alt2"># BEGIN WordPress</div> <div class="line number2 index1 alt1">RewriteEngine On</div> <div class="line number3 index2 alt2">RewriteBase /</div> <div class="line number4 index3 alt1">RewriteRule ^index.php$ - [L]</div> <div class="line number5 index4 alt2">RewriteCond %{REQUEST_FILENAME} !-f</div> <div class="line number6 index5 alt1">RewriteCond %{REQUEST_FILENAME} !-d</div> <div class="line number7 index6 alt2">RewriteRule . /index.php [L]</div> <div class="line number8 index7 alt1">END WordPress</div> </div>

</div>
</div>
</div>
 

以上代码是WordPress自动生成的伪静态文件 .htaccess
<div class="cnblogs_Highlighter sh-gutter">
<div>
<div id="highlighter_100423" class="syntaxhighlighter php">

<div class="line number1 index0 alt2">1</div> <div class="line number2 index1 alt1">2</div> <div class="line number3 index2 alt2">3</div> <div class="container"> <div class="line number1 index0 alt2">RewriteEngine On</div> <div class="line number2 index1 alt1">RewriteCond %{SERVER_PORT} !^443$</div> <div class="line number3 index2 alt2">RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]</div> </div>

</div>
</div>
</div>
 

将以上代码粘贴复制到  #END WordPress 之前并保存即可。

这时候我们在访问自己WordPress站点的时候就强制跳转到https小绿标锁状态了。

Last modification:March 5th, 2020 at 03:25 pm
如果觉得我的文章对你有用,请随意打赏