wordpress从http跳转到https然后回到http然后最终到https

时间:2017-10-28 16:49:09

标签: wordpress .htaccess https http-redirect

我的Wordpress网站在https://www.example.com

下的Wordpress管理员中为Settings/general

我正在使用Simple SSL插件。这是我的.htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteCond %{HTTP_HOST} =example.com
#RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} wp-admin
RewriteRule ^(.*)$ https://www.example.com/wp-admin/ [R,L]
</IfModule>



# BEGIN rlrssslReallySimpleSSL rsssl_version[2.5.22]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL

出于某种原因,当转到example.com时,它会从http-&gt; https-&gt; http-&gt; https

进行3次重定向
example.com
https://example.com
http://www.example.com
https://www.example.com

1 个答案:

答案 0 :(得分:0)

如果X-Forwarded-Proto是确定请求是否来自HTTPS的方式,我相信您可以用以下内容替换所有内容:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://www.example.org%{REQUEST_URI} [R=301,L]
</IfModule>

将它放在.htaccess中的WP块之前。如果直接在Apache中处理SSL,请将RewriteCond行替换为RewriteCond %{SERVER_PORT} 80