Add the following two lines of code into the .htaccess
file:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
WARNING: For testing purposes, you might want to remove the [L,R=301]
condition from the second line and instead just use [L,R]
. R=301
will make your browser PERMANENTLY redirect to the new URL and there's no way you can break out of that if you missconfigure your .htaccess
file! You might get around the mistake, but your users WON'T!
Your final .htaccess
should look like this: