HTTP to HTTPS redirection using .htaccess file

We can redirect the non SSL query of your website to SSL port by using .htaccess file in the website’s public folder. If the file is not there, you can simply create it.

1- Create/Open the file .htaccess
2- Add the following redirect rule.

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

If your site is in a sub-folder, use this code:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} folder 
RewriteRule ^(.*)$$1 [R,L]

Don’t forget to replace with your actual domain name.

How to add HTTP to HTTPS redirection rule from cPanel?

You can also define the redirect rule from the cPanel of the website. Please follow the steps given below:

1- Log into cPanel.
2- Click to “Redirects” under “Domains” tab.
3- Define rule from here.

http to https redirection using .htaccess


That’s it.

Leave a Reply

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