【发布时间】:2020-02-12 07:47:22
【问题描述】:
当多个域指向同一个服务器时,需要将一个非https域重定向到https。 具体来说,所有非 www 域都需要重定向到 www,并且只有一个域需要重定向到 www 以及 https。
例如,具有 SSL 的域
http://example.com to https://www.example.com
http://www.example.com to https://www.example.com
https://example.com to https://www.example.com
域没有 SSL
http://example2.com to http://www.example2.com
http://example3.com to http://www.example3.com
我已经尝试了许多 stackoverflow 上提供的解决方案,例如 this。
我当前的 htaccess 如下所示,
#redirect to https - domain that having SSL
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
#all other non www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
除了一种情况外,一切正常。当我使用具有 SSL 的 www (http://www.example.com) 进入域时,不重定向到 https。
【问题讨论】: