Redirect mapped sub-domain

I have a domain with SSL certificate only for the non-www version(example.com), and mapped that to a sub-domain on a multisite.

The issue is when I try to reach the domain(with www) either at https://www.example.com or http://www.example.com I get an invalid certificate error. While entering the domain without www works properly.

Is there any way I could set a redirect from the multisite(or htaccess) for the mapped domain, that will send all requests for https://www.example.com to https://example.com(domain with SSL) version.

Note, tried redirect from cpanel and the following htaccess rewrite but doesn't help:

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