将http://示例redirect到http://www.example.com,并将https://example.comredirect到https://www.example.com

正如问题所述,我想将http://示例redirect到http://www.example.com和https://example.com到https://www.example.com 。

我试过了apache重写规则:

RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] #jmv-this should work, but does not RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

但只有http://example.com被redirect到http://www.example.com 。 当我去https://example.com我留在https://example.com

我认为这些规则应该工作。 有什么问题?

configuration中其他地方的AllowOverride可能会无意中禁用.htaccess文件的使用 – 这似乎在这里!