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 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

How to Create a Full cPanel Backup

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

How to Install WordPress Manually Using cPanel

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

How to Create a Database in cPanel (MySQL Database)

1. From the home page of your HayHost client area, then click  "SERVICES".   2. In the "My...

How to Create a Subdomain in cPanel

This article will go over creating a Subdomain under your cPanel account. Log into cPanel on...