Our server tech support team often gets tickets like how to make http:// or http://www. redirect to https:// or https://www. Often the answer is simple, but for the newbies and yours use, I am putting it here.
First requirement is to have an SSL certificate installed. Add the following lines in a .htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I assume when you directly access https://www.domainname.com , the site loads fine.