伙计们,我有一个小问题,迁移网站从HTTP到HTTPS。
我想强制所有到www https
http://example.com
-〉https://www.example.com
(工作)http://www.example.com
-〉https.www.example.com
(不工作)
上面的例子返回两个www.www的url
https.www.www.example.com
我的代码
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
我做错了什么?
1条答案
按热度按时间fcy6dtqo1#
您可以使用此重定向将
http -> https
和www
重定向合并到一个规则中:验证
R=302
工作正常后,将其替换为R=301
。测试mod_rewrite
规则时,请避免使用R=301
(永久重定向)。另一方面,你的规则是在重定向后试图保持相同的方案(http或https)。你的规则也适用于
www
缺失的情况。你需要在两个条件之间使用OR
,正如我在答案中所示。