How to Redirect a Website from HTTP to HTTPS using .htaccess

If you do not have a .htaccess file, create a .htaccess file in the public_html folder or in the root folder of the site.


1. Write the following code to the file:

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

2. If the .htaccess file already exists 

Don't duplicate RewriteEngine On.
Ensure that lines starting with RewriteCond and RewriteRule immediately follow RewriteEngine On.

  • http, https, redirect
  • 125 Users Found This Useful
Was this answer helpful?

Related Articles

How to Unblock IP Address in Server Firewall

If your IP address was blocked by mistake, you can easily unblock your IP address from the...

How to Create a Full cPanel Backup

1. From the home page of your HayHost client area, navigate to the "Your Active...

How to Deploy/Host your React App on Shared Hosting in cPanel

1. Purchase a Domain and Hosting To host a website and you plan to host your React app, first,...

How to Install WordPress Manually Using cPanel

1. From the home page of your HayHost client area, navigate to the "Your Active...