How to Force HTTPS using .htaccess (Updated 2021)

Admin

Administrator
Admin - Administrator  
After installing an SSL certificate, your website is available over HTTP and HTTPS. However, it’s better to use only the latter because it encrypts and secures your website’s data. While This tutorial will show you how.

Forcing HTTPS on All Traffic
Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Forcing HTTPS on a Specific Domain
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain1.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Forcing HTTPS on a Specific Folder
Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(folder1|folder2|folder3) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

After making the changes, clear your browser’s cache and try to connect to your site via HTTP. If everything was added correctly, the browser will redirect you to the HTTPS version.
 

Leave a Reply

What you're looking for ?

Looking for best VoIP soultions?
Get Quote
OR
Looking for experts to setup, configure, customization, CRM intergration, REST API's, web-hooks, password ptotected directories and more for your system?
Talk to Experts
Top