This is a very simple alternative:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com%{REQUEST_URI} [R,L]
If you prefer everything to go to without www, exchange the last line for:
RewriteRule ^.*$ https://domain.com%{REQUEST_URI} [R,L]
If you prefer to keep the www typed equal, exchange the last line for:
RewriteRule ^.*$ https://%1domain.com%{REQUEST_URI} [R,L]
Remembering that if you put the certificate in the same IP of the sites SEM certificate, and someone tries to access https://site-sem-certificado.com.br will give error anyway, because the negotiation of SSL comes before Apache process the page.
And that’s why SSL places you in exclusive IP (or if you spend money on certificates for multiple domains).
I got that answer from here
The rewritebase is probably wrong.
– Guilherme Nascimento