[英]http://example.com, http://www.example.com and https://example.com to https://www.example.com
[英]htaccess rewrite http://example.com to http://www.example.com but https://www.example.com to https://example.com
使用.htaccess重写,我希望拥有:
http://example.com
重定向到: http://www.example.com
: http://www.example.com
https://www.example.com
重定向到: https://example.com
: http://example.com
哪个是最好的方法?
我开始于:
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
您需要2条规则:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.