This really isn't a php question. I was just hoping someone here might have some experience with rewrite and apache.
I would like to convert the following
http://www.domain.com
www.domain.com
domain.com
https://domain.com
to
https://www.domain.com
The closest I gotten is with the following.
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
This does everything I need except if I type https://domain.com I get a certificate mismatch error. The browser asks if I want to proceed or not and if I do then it rewrites correctly to https://www.domain.com. Is there a way to prevent this other than purchasing another certificate for https://domain.com?
I understand why I'm getting the error. I was hoping the rewrite would circumvent this?