【发布时间】:2015-10-21 10:03:50
【问题描述】:
我已将hole webstore 更改为https。所以我想将除移动子域(http://m.my-store.com)之外的所有域重写为https://www.my-store.com
#First rewrite any request to the wrong domain to use the correct one (here www.)
#mobile subdomain shouldn't rewrite
RewriteCond %{HTTP_HOST} !m\.
RewriteCond %{HTTP_HOST} !^www\.my-store\.com$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.my-store\.com$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
结果:
http://my-store.com OK (correct rewrite to https://www.my-store.com)
http://www.my-store.com OK (correct rewrite to https://www.my-store.com)
https://my-store.com X (stays with https://my-store.com)
https://www.my-store.com OK (correct rewrite to https://www.my-store.com)
http://m.my-store.com OK (correct rewrite to https://www.my-store.com)
【问题讨论】:
-
http://m.my-store.com OK (correct rewrite to https://www.my-store.com) -
抱歉,复制和粘贴错误。应该是m.my-store.com OK(留在m.my-store.com)
-
https://my-store.com保持相同的 URL,这不是你想要的吗? -
不,我想将 URL
(https://my-store.com)重定向到 URL(https://www.my-store.com) -
由于您只有 %{HTTP_HOST} 作为目标,它不会在您的第三个示例中将 www 添加到 URL。您可能需要创建两组来添加 https(一组用于 m.my-store.com,一组用于其他)
标签: apache .htaccess mod-rewrite redirect https