HTTPS强制重定向无法在Wordpress中运行

PF *_*ing 14 apache wordpress .htaccess mod-rewrite redirect

我的Wordpress目录位于www.example.com/blog

我最近改变了整个网站以强制使用HTTPS.所以/ blog /中的.htaccess文件如下所示:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Run Code Online (Sandbox Code Playgroud)

我还将Wordpress设置中的站点URL更改为HTTPS.

这在主页中完美运行,但在任何帖子页面中,最终用户都可以通过更改URL并按Enter键更改为非安全HTTP.

例如,他们可以直接输入:http://www.example.com/blog/post-1/,它将作为HTTP加载.

我的.htaccess文件有什么问题?松散的结局在哪里?

anu*_*ava 33

更改规则的顺序.首先重定向到https然后让WP接管你的所有请求.

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)