How to force redirect any typed web address to https www

Considering the fact that an user can type into the browser address my domain address as any one of the following:

mydomain.com
www.mydomain.com
http://www.mydomain.com
https://mydomain.com
https://www.mydomain.com

How can I always redirect instantly to https://www.mydomain.com ?
This becomes somewhat important as https:// and https://www show different font sizes of a default install of Elgg. (why this is so?)
Also sometimes such redirection gives login error : login from different domain not allowed (what to do to avoid this?)

I am trying the following but not getting desired results uniformly

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