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:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
</IfModule>
# END WordPress
If this was useful, you can buy me a coffee here. Thank you!