在 htaccess 中从裸 http 和 https 域重定向到 https://www 域?

Doing a redirect from naked http & https domain to https://www domain in htaccess?

这个解决方案

似乎对我不起作用。我想要..(与 OP 相同)

http://example.com
http://www.example.com
https://example.com

全部重定向到 https://www.example.com

我已经尝试了很多解决方案,但似乎没有任何效果。

详情:

-我为站点的 www.example.com 版本安装了 ssl。 -运行 wordpress -试过 ssl 插件但没有任何效果 - 尝试了以下 htaccess 规则,第一个似乎没有做任何事情,第二个导致无限循环

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

第二次尝试...

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www\.)?your domain name\.com$ [NC]
RewriteRule ^$ https://www.your domain name.com/%{REQUEST_URI} [R,L]

这个引起了循环..

我开始认为我的方法是错误的。其中一个不应该工作吗?如果没有,我该如何在 www 子域上完全保护此站点

这就是您需要做的,才能将所有内容合二为一。

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !^on
RewriteRule ^(.*)$ https://www.yoursite.com/ [R=301,L]

显然将 yoursite.com 替换为您的真实域名。让我知道这对你有何影响。