Apache 如何使用.htaccess(例如.com)强制HTTPS?

Apache 如何使用.htaccess(例如.com)强制HTTPS?,apache,.htaccess,Apache,.htaccess,我想强制一个站点使用https,但它只在我键入www.example.com时有效,而在我使用example.com时无效。这是我的htaccess文件: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 你们能帮我吗?然后把这些行放在HTTPS条件之上 RewriteEngine On RewriteCond %{HTTP_HOST} ^w

我想强制一个站点使用https,但它只在我键入www.example.com时有效,而在我使用example.com时无效。这是我的htaccess文件:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

你们能帮我吗?

然后把这些行放在HTTPS条件之上

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ "https\:\/\/example\.com\/$1" [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
更改为
RewriteRule^(.*)$https://example.com/$1[R=301,L]
无需在https之前重定向到http