Rewrite www to non www under sub vhost

Under main domain I have set redirect which works fine (domain.com):

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

However it does not work for sub servers (sub.domain.com) and I don’t know why.

Under Virtualmin config I have also set redirect http to https

Thanks,