Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache2 redirect to another domain with ssl

I have a no clue why this fails. I just want to redirect all domain to www.maindomain.com and also http to https, what am i missing?

# redirect http to https    
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# redirect without www to www
RewriteCond %{http_host} ^maindomain.com [nc]
RewriteRule ^(.*)$ https://www.maindomain.com  [r=301,nc]

# redirect another domain to www.maindomain.com    
RewriteCond %{HTTPS} off # this i was missing 
RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain.com [NC]
RewriteRule ^(.*)$ https://www.maindomain.com [R=301,L]
  1. http://maindomain.com to https:/www.maindomain.com/ works
  2. http://anotherdomain.com to https:/www.maindomain.com/ works
  3. https://anotherdomain.com to https:/www.maindomain.com/ fails
like image 813
Daniel Krahofer Avatar asked Nov 09 '22 20:11

Daniel Krahofer


1 Answers

The Http to Https redirection for Another domain failed because Your Rule is missing the following line :

RewriteCond %{HTTPS} off

Try :

# redirect another domain to www.maindomain.com    

RewriteCond %{HTTPS} off

RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain.com [NC]
RewriteRule ^(.*)$ https://www.maindomain.com [R=301,L]
like image 61
Amit Verma Avatar answered Nov 15 '22 07:11

Amit Verma