I am struggling with setting proper https redirect via a .htaccess file for my domains. I have the following domains, subdomains and directories:
public_html/ -> www.red.com
public_html/drk -> dark.red.com
public_html/blue -> www.blue.com
How am I supposed to write the .htaccess file(s) so that the redirect works properly?
Currently I have this in my .htaccess file:
RewriteEngine On
RewriteOptions inherit
RewriteCond %{HTTP_HOST} ^(www\.)?red\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://red.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^(www\.)?dark\.red\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://dark.red.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^(www\.)?blue\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://blue.com%{REQUEST_URI} [R=301,L,NE]
Redirect works for the main site (www.red.com) but not for the other two sites. If I remove the rules for the other two sites, redirect sends me to www.red.com/drk instead of dark.red.com and to www.red.com/blue instead of www.blue.com.