使用.htaccess重定向到https

使用.htaccess重定向到https,.htaccess,redirect,ssl,certificate,.htaccess,Redirect,Ssl,Certificate,我对.htaccess有问题 我的服务器中有一个证书,它只用于(不用于)因此,我正在尝试将.htaccess重定向到正确的url 我的意图是: http://www.example.com --> https://example.com http://example.com --> https://example.com https://www.example.com --> https://example.com 我尝试了不同的组合,但似乎没有任何效果。目前,我有这个,但似

我对.htaccess有问题

我的服务器中有一个证书,它只用于(不用于)因此,我正在尝试将.htaccess重定向到正确的url

我的意图是:

http://www.example.com --> https://example.com
http://example.com --> https://example.com
https://www.example.com --> https://example.com
我尝试了不同的组合,但似乎没有任何效果。目前,我有这个,但似乎是不工作的

http://www.example.com/subfolder
,我不知道什么失败了

RewriteEngine On

# Follow symbolic links.
Options +FollowSymLinks

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

# Prevent directory listings
Options All -Indexes

用此代码替换当前代码

Options -Indexes +FollowSymLinks
RewriteEngine On

# redirect "www" domain to https://example.com
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# redirect http to https (at this point, domain is without "www")
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

那个代码对我不起作用,我发现,这对我有效

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

“似乎什么都不管用”是什么意思?它怎么不起作用?浏览器是否抱怨混合内容?看,我是说我试过的任何一种不同的组合。htaccess似乎很有效。。。结果出乎意料。