Force 301 redirect to https:// and www. with .htaccess

Here’s how to 301 redirect all traffic to https://www. Add the following to your .htaccess file:

RewriteEngine on
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.yourdomain.com%{REQUEST_URI} [L,R=301]

This redirects all traffic to go from:

http://yourdomain.com
http://www.yourdomain.com
https://yourdomain.com

To: https://www.yourdomain.com