Autobook Facebook
Autobook Facebook

Reputation: 33

redirect to http to https for multiple domain

We have server having 2 domains

1) exmaple.co

2) exmaple.com.au

If User hits first domain "example.co"

http://www.exmaple.co OR http://exmaple.co then it should be redirect to

https://exmaple.co

If User hits second domain "example.com.au"

http://www.exmaple.com.au OR http://exmaple.com.au then it should be redirect to

https://exmaple.com.au

We have purchase SSL.

We have use framework Codeigniter set the coding in 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]

If i use above code then it's goes on redirect loop.

Upvotes: 2

Views: 2321

Answers (2)

Amit Verma
Amit Verma

Reputation: 41219

Try :

RewriteEngine on


RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.(example\.com\.au|example\.co)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]

This rule will redirect :

or

to https non-www

Upvotes: 0

Andreas Scheibleger
Andreas Scheibleger

Reputation: 297

You are getting infinite redirect loop because you are not preventing the redirect to happen at all.

To achieve what you are trying to do:

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]

Upvotes: 1

Related Questions