0

I know this has been answered in other posts (https://stackoverflow.com/a/25196859/730378 and https://stackoverflow.com/a/20915595/730378), but I've tried them both and neither are working for me.

Using the htaccess code below works to redirect to https for the root domain and the aliases, but the subdomain keeps redirecting and using https for the subdomain as well, which I don't want.

####
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !=subdomain.rootdomain.ca [NC,OR]
RewriteCond %{HTTP_HOST} ^(www.)?rootdomain.ca$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www.)?rootdomain.biz$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www.)?rootdomain.co$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www.)?domainalias.biz$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www.)?domainalias.ca$ [NC]
RewriteRule (.*) https://rootdomain.ca/$1 [R=301,L]
Community
  • 1
  • 1
spiderling
  • 139
  • 1
  • 2
  • 11
  • 1
    This rule should work as is. Most likely the subdomain is redirected from earlier experiments with `R=301`. *Never* test with [`R=301`](http://stackoverflow.com/a/9204355/1741542)! – Olaf Dietsche Sep 18 '16 at 17:06
  • As @PanamaJack already mentioned, you don't even need the first `RewriteCond`. – Olaf Dietsche Sep 18 '16 at 17:07

1 Answers1

1

Your should use !^ instead of != on the first condition but technically you don't even need the first one. It will only redirect to root if it matches the root domains or aliases. Consolidate all those conditions and try your code this way. Clear your cache and give this try.

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(rootdomain|domainalias)\.(ca|biz|co)$ [NC]
RewriteRule (.*) https://rootdomain.ca/$1 [R=301,L]
Panama Jack
  • 24,158
  • 10
  • 63
  • 95