How to Force HTTP to HTTPS using .htaccess

Redirect all URL HTTP traffic to HTTPS, i.e. permanently redirect old URL to new URL.

Follow these steps:

  • Open .htaccess file
  • find RewriteEngine On and copy-paste these codes
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Note: Make sure the line RewriteEngine On is not repeated twice.