I have a domain domain.com
that I use as my primary domain. I also own a second domain domain2.com
that I have automatically go to domain.com
This is done with .htaccess:
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
I want to set up a subdomain sub.domain.com
but with that current .htaccess, visiting sub.domain.com sends me to www.domain.com/sub
I found this question, which solves this problem, but negates my first issue of domain2.com
pointing to domain.com
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I'm looking for a way to combine the two rules:
www.domain.com
=> www.domain.com
domain.com
=> www.domain.com
domain2.com
=> www.domain.com
sub.domain.com
=> sub.domain.com