我需要将www和非www重定向到https。我到处都是关于stackoverflow的内容,但是找不到我想要的东西。
规则是:
我目前有:
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
但是,如果有人输入www.example.com,它仍会使用http版本而不是https。
我想我实际上需要的是RewriteCond正则表达式,使其完全匹配,并且仅匹配“ example.com”和“ www.example.com”
谢谢
您可以使用以下规则通过一次重定向将非www或www重定向到https:// www
#redirect http non-www to https://www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
#redirect https non-www to www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
在测试此规则之前,请清除浏览器的缓存。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句