繁体   English   中英

htaccess将http://example.com重写为http://www.example.com,但将https://www.example.com重写为https://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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM