I want to rewrite http://
, http://www.
https://www.
and nonexistent subdomain variations to https://domain.com
. A nonexistent subdomain variation might be http://abc.domain.com
and https://abc.domain.com
. To complicate matters further, I want to keep trailing URLs, and prevent redirecting existing subdomains. AND, some existing subdomains use http while others use https.
This is what I have so far:
#don't redirect existing subdomains example1 or example2
RewriteCond %{HTTP_HOST} ^((example1|example2)\.)?domain\.com$
RewriteRule .* - [L]
##redirect http, wildcard subdomains, and www. with appended trailing URLs
RewriteCond %{HTTP_HOST} . [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
Thanks in advance.