Redirect http to https using .htaccess file in wordpress

To redirect visitors to the https section of your website, use the following code. This code should be included with the mod rewrite code for WordPress permalinks.

Warning: be careful with htaccess files as incorrect code can break the website. Remember to test afterwards making sure your site is working as it should.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Its important to have a 301 redirect in place otherwise Google will see both http and https versions of your website. This could lead to a duplicate content penalty (sad face).