How to apply Force HTTPS redirection

By Raman Kumar

Updated on Jun 03, 2024

To redirect http to https on free or premium web hosting, you need to add below lines in your sites-

RewriteEngine On
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

You can force both www and https using below lines-

RewriteEngine On
RewriteCond %{ENV:HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www.YOURDOMAIN.COM$ [NC]
RewriteRule ^(.*)$ https://www.YOURDOMAIN.COM/$1 [L,R=301]