htaccess - redirect non-www to www with HTTPS
If you would like to redirect visitors to your web site from the non-www version (e.g. hostingmatters.co.uk) to the www version (www.hostingmatters.co.uk) whilst also redirecting them to the https version of the site, then you can do so using this addition to your htaccess file:
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.hostingmatters.co.uk%{REQUEST_URI} [L,R=301]
Simply copy and paste these lines to the top of your htaccess file and then replace 'hostingmatters.co.uk' with your web site's own address.
This will redirect visitors trying to go to:
to
https://www.example.com