我正在尝试将三个案例重定向到 https://www 。他们是:
http://
http://www
https://
我能够得到前两个,但不能得到最后一个。这是我使用的:
RewriteCond %{HTTPS} 关闭
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://www.%1%{REQUEST_URI} [L,R=301]
最佳答案
您可以使用此规则在同一规则中添加 www 并启用 https:
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
要从 %{HTTP_HOST}
捕获值,您需要一个不是 OR
条件的条件。
关于.htaccess - htaccess 将所有流量重定向到 https ://www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34658449/