I know there are many similar threads, but none of them seems to match my exact problem. Here is what I’m trying to do:
(1) http://www.mydomain.com/ -> ht
I found the following answer would match to your requirement:
www to non-www with https but no other subdomains
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Fulfill all of the three (3) conditions:
(1) http://www.example.com/ -> https://example.com/
(2) http://example.com/ -> https://example.com/
(3) https://www.example.com -> https://example.com/
but no other subdomains than www like so:
(4) http://others.example.com -> https://others.example.com/
(5) https://others.example.com -> https://others.example.com/