Redirect https://www to https://non www

Hello, I’m creating a wordpress multisite with subdomains and a letsencrypt wildcard ssl cert, everything is working fine except for this…
I’m having problems with htaccess redirection.
I’m using this code

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.)$ [NC]
RewriteRule ^(.
)$ https://%1/$1 [R=301,L]

in htaccess to redirect http://, http://www. and www. to https://non www and it is working fine. For example it will redirect http://subdomain.mainsite.com to https://subdomain.mainsite.com and www.subdomain.mainsite.com to https://subdomain.mainsite.com.
But if i try to open https://www.subdomain.mainsite.com it will not redirect to https://non www creating an ssl cert error.
What I’m doing wrong?

Hello and thanks in advance for your help. I’m looking to redirect https://www..maindomain.com to http://.maindomain.com.
I did achieve success with http to https, but no luck trying to redirect https://www to https non www
Any help?

My reasonr for this is that https://www.*.maindomain.com is breaking ssl