【发布时间】:2016-08-26 23:28:51
【问题描述】:
我有 3 个网址并且有 ssl 认证
1) www.example.com
2) myexample.com
3) otherexample.com
我需要将以上三个网址都重定向到 https 安全网址 例如: 当用户打开上面的任何一个 url 时,它应该重定向到 https url。
=> when user open www.example.com OR example.com >>> it should redirect to https://www.example.com
=> when user open www.myexample.com OR myexample.com OR https://www.myexample.com >>> it should redirect to https://myexample.com
=> when user open www.otherexample.com OR otherexample.com OR https://www.otherexample.com >>> it should redirect to https://otherexample.com
注意:我有 www.example.com、myexample.com(non-www)、otherexample.com(non-www) 的 ssl 证书
我需要帮助来解决我的问题。我也想动态设置规则,所以将来如果我有更多的 url,就不会编辑 .htaccess 文件。 (如果可以从下面的 {HTTP_HOST} 设置规则中删除“www”,这样对我有好处)
我在 htaccess 中设置了一些规则,但它对我不起作用。
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
#rule for myexample.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [nocase]
RewriteRule ^(.*) https://example.com/$1 [last,redirect=301]
#rule for otherexample.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.otherexample.com [nocase]
RewriteRule ^(.*) https://otherexample.com/$1 [last,redirect=301]
【问题讨论】:
标签: php apache .htaccess redirect ssl