簡體   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