force HTTPS using htaccess

You need to on your website. As a website developer or owner, it's important to have your website secure at all times and SSL is a good way to ensure your visitors will trust your site.

One thing you must not allow is having browsers like Chrome and Firefox to be showing insecure warnings on sites without SSL certificates. Without SSL, your website will show insecure to visitors.

Therefore, using an SSL-encrypted connection for safety, accessibility, or PCI compliance reasons is necessary. It becomes very important to redirect from HTTP to HTTPS.

READ ALSO: How To Launch Your Own Personal Website in Minutes [The Easy Way & The DIY Way]

How To Redirect HTTP to HTTPS using .htaccess [Force HTTPS Using htaccess]

force HTTPS using htaccess

There are three (3) ways to force and I'll explain each method/option below.

Option 1. Forcing HTTPS on All Traffic

One of the many functions you can perform via .htaccess is the 301 redirects, which permanently redirects an old URL to a new one. You can activate the feature to force HTTPS on all incoming traffic by following these steps:

Step 1. Go to File Manager in your hosting panel and open .htaccess inside the public_html folder. If you can't locate it, sure to create or unhide it.

Step 2. Scroll down to find RewriteEngine On and insert the following lines of code below it:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} 

Save the changes.

Important! Make sure that the line RewriteEngine On is not repeated twice. In case the line already exists, simply copy the rest of the code without it. 

READ ALSO: How To Setup Rapyd Payment Gateway on Your Website

Option 2. Forcing HTTPS on a Specific Domain

Let's say that you have two domains: and Both domains access the same website, but you only want the first one to be redirected to the HTTPS version. In this case, you need to use the following code:

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

Make sure to replace yourdomain1 with the actual domain you're trying to force HTTPS on.

Option 3. Forcing HTTPS on a Specific Folder

The .htaccess file can also be used to force HTTPS on specific folders.

However, the file should be placed in the folder that will have the HTTPS connection.

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(folder1|folder2|folder3) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

Make sure to change the folder references to the actual directory names.

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.

READ ALSO: Rank Math SEO Solutions – The Holy Grail Of Website Ranking and SEO Mastery

FAQs on htaccess Redirect

READ ALSO: Detailed Guide On How To Design A Professional Website and Blog For Your Business


There you have it, ‘ force HTTPS using htaccess'. Now, you have successfully edited your .htaccess file and redirected all HTTP traffic to HTTPS, the safe version of your website.

Depending on the platform where you developed your website, there could be alternative methods to enable this feature. For example, you can configure your or PrestaShop site to work with HTTPS using plugins.

Discover more from Detailed Guide Blog

Subscribe to get the latest posts to your email.

1 comment
Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like
Zuri/HNG Internship

Zuri/HNG Internship 9.0 for Nigerian Creatives

Are you a Nigerian Creative person? The Zuri/HNG Internship is open for…
How To Watch Youtube On Samsung Smart TV

How To Watch Youtube On Samsung Smart TV

Samsung Smart TVs, equipped with cutting-edge technology, offer a fantastic viewing experience.…
How to Refinance a Personal Loan

Best Tips on How to Refinance a Personal Loan

Do you know? Many people don’t know how to refinance a personal…
Samsung Galaxy S8

How Big Is A Samsung Galaxy S8?

The fact is that the Samsung Galaxy S8 is about the same…