How to redirect http to https using .htaccess?

If you have installed SSL Certificate on your website and want to redirect your website traffic from http to https using .htaccess then you need to add the below code to your .htaccess file for the redirection. 

Redirecting HTTP to HTTPS

Add the following line to your .htaccess, if you are looking to redirect a specific domain from HTTP to HTTPS.

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

Add the following line to your .htaccess, if you are looking to redirect a specific folder from HTTP to HTTPS.

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

Note: You will need to replace example.com with your domain where required in your code and set the folder name where it is required. 

Related Articles

How to remove files that are more than 100 MB inside the public_html folder in cPanel server ?

Please run the below command to find out the files that are more than 100 MB inside your cPanel...

How to Disable SELinux on CentOS?

SELinux called Security-Enhanced Linux is a security module of Linux kernel which provides...

How to allow or block the port and IP Address using Firewalld, IP tables, and UFW in Linux?

On Linux, the firewall is essential to control the incoming and outgoing network traffic. It is...

Do you offer apache web service with controlpanel option?

Yes, we do offer apache web service with controlpanel like cPanel and Plesk. Both of these...

How to Manage Linux Cloud VPS From Client Area?

This article will assist you to manage your Linux Cloud VPS from client area (though you will...

  • 0 Users Found This Useful

Was this answer helpful?