多个域重定向到http到https

时间:2016-06-14 06:06:47

标签: .htaccess redirect

我们有2个域的服务器

1)exmaple.co

2)exmaple.com.au

如果用户点击第一个域“example.co”

http://www.exmaple.cohttp://exmaple.co然后它应该重定向到

https://exmaple.co

如果用户点击第二个域“example.com.au”

http://www.exmaple.com.auhttp://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]

如果我使用上面的代码,那么它将继续进行重定向循环。

2 个答案:

答案 0 :(得分:0)

您正在获得无限重定向循环,因为您根本没有阻止重定向发生。

要实现您的目标:

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]

答案 1 :(得分:0)

尝试:

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

相关问题