How to redirect http to HTTPS from .htaccess

Every web developer or single individual who is working on language based website looking for the metod “How to redirect http to HTTPS from .htaccess

What is .htaccess?

.htaccess is an file which works on apache based server which is been used to add/enabel some more additonal functionality.

These facilities include basic redirect functionality, for instance if a 404 file not found error occurs.

In this article, we are going to see how to redirect HTTP to HTTPS from .htaccess by cPanel.

  • Login to cPanel
cPanel Dashboard

  • Navigate to File Manager > Public_html
  • Click on Setting Icon.
We are at location – cPanel > File Manager > public_html
  • Now check Show Hidden Files (dotfiles).
This will show hidden files such as .htaccess, .well-known directory, etc.
  • Now click on .htaccess file & click on edit
  • Now add the below code in .htaccess file and save it.

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

Conclusion –

As a result your website all connections will be redirected from http to https. If you have  installed the SSL on your website this will increase your website trust and may increase sales/visitors flow.

About the Author: Reform Hosting

Reform Hosting is a leading Hosting Service provider, offering reliable, scalable solutions for customers of all sizes and services. We supply all of the servers, software, bandwidth and management tools needed to run almost any web hosted application – from small to enterprise server solutions. We are committed to excellent quality Service. Our staff has over 2+ years of experience in the IT field.

You May Also Like


Leave a Reply

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