Home » How to Redirect HTTP to HTTPS Using .htaccess – Easy steps
How to

How to Redirect HTTP to HTTPS Using .htaccess – Easy steps

In this tutorial, we will discuss How to Redirect HTTP to HTTPS Using .htaccess in simple and easy steps. We will discuss many techniques for HTTP to HTTPS redirection using .htaccess.

Firefox and Chrome show an insecure warning to the users for Non-SSL sites. So, site owners can’t get the proper traffic without SSL. Most of the user left the site because of insecure warning. Therefore, it is necessary to have an SSL-encrypted connection for all the genuine site owners.

When you purchase SSL then it’s important to Redirect HTTP to HTTPS. Search engines can’t track your website is secure without redirection. These all possible by some changes in the .htaccess file.

Redirect HTTP to HTTPS Using .htaccess

First of all, you have to know about the “.htaccess file” , where to find it and edit it. You can easily fix force SSL with .htaccess. I will tell you how you can do it. Just follow the steps below. If you have enough knowledge of .htaccess file then you can skip this step.

What is .htaccess file?

In this file, there is some instructions/code which tells the server how to act before site load. There is mostly two type of instructions.

  1. Rewriting
  2. Redirects
How to edit .htaccess file?

Two ways to edit the .htaccess file.

  1. From FTP (Using FileZilla)
  2. From Cpanel
1) From FTP (Using FileZilla)

You can save the file in your computer and then upload a file using FTP (You need FileZilla Software). Another option is you can directly open FTP, edit the file in a text editor like Notepad++ and save it.

2) From Cpanel

Note: First of all, take a full backup of your website. If anything goes wrong you can restore your website.

  1. Login into Cpanel. ( “https://www.example.com/cpanel” OR “https://www.example.com:2082” )
  2. Now go to “File Manager”.
  3. Select domain name (If you have subdomain or anything else) OR Click “public_html”.
  4. Now you are reach at the root of your web directory.
  5. If you can’t find “.htaccess” file click on “Settings” (Upper Right Corner). Then Check “Show Hidden Files (dotfiles)” and Save.
  6. Now right click on .htaccess tab and select “Edit File” option
  7. Maybe one popup will come. Click on “Edit”.
  8. Finally new window will open with .htaccesss file code.
  9. At Last Edit the file and Save.

Redirect HTTP to HTTPS Using .htaccess

Note: In below code snippet replace “yourdomain” + “folder” with your actual domain name and folder name.

1) Force SSL with .htaccess

HTTPS Connection will be forcefully applied by adding this code in your .htaccess file.


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

2) Redirect to a Specific Domain

Rather you can add this code for the redirect HTTPS to a specific domain.


RewriteEngine On 
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/\ [R,L]

3) Redirect to a Specific Folder

Furthermore, you can force SSL to a specific folder. All the following code.


RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} folder 
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/\ [R,L]

Finally, your site is now redirecting HTTP to HTTPS. You can use this code on any website platforms like PHP, WordPress, Magento, Joomla, etc…

I hope you liked this article. Please spread the love to share it with your friends.

Releated Article: