重定向HTTP到HTTPS为多个域
问题描述:
我们已经具有服务器2个域重定向HTTP到HTTPS为多个域
1)exmaple.co
2)exmaple.com.au
如果用户点击第一结构域“example.co “
http://www.exmaple.co
或http://exmaple.co
那么就应该重定向到
https://exmaple.co
如果用户点击第二个域 “example.com.au”
http://www.exmaple.com.au
OR http://exmaple.com.au
那么它应该是 重定向到
https://exmaple.com.au
我们有购买SSL。
我们有使用框架Codeigniter在htaccess中设置编码。
RewriteCond %{HTTP_HOST} ^exmaple.co [NC]
RewriteRule ^(.*)$ http://exmaple.co/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^exmaple.com.au [NC]
RewriteRule ^(.*)$ http://www.exmaple.com.au/$1 [L,R=301]
如果我使用上面的代码,那么它会进行重定向循环。
答
您正在获得无限的重定向循环,因为您并未阻止重定向发生。
要达到什么样的你正在尝试做的:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example\.co$
RewriteRule ^(.*)$ https://example.co/$1 [L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com\.au$
RewriteRule ^(.*)$ https://example.com.au/$1 [L]
答
尝试:
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.(example\.com\.au|example\.co)$
RewriteRule^https://%1%{REQUEST_URI} [NE,L,R]
此规则将重定向:
或
到https非www