How to Redirect HTTP to HTTPS URL

Create .htaccess File

Create a file with .htaccess extension in the root directory of the website domain. It will be a simple text file and you can edit this file with any text editor.

Redirect HTTP to HTTPS URL

If the secure certificate (SSL) was installed on your website, you can redirect visitors to the secure web version. Sometimes SSL encrypted connection is necessary for your website. This means you would like to force website visitors to use SSL by automatically redirecting HTTP to HTTPS version of the URL.

Add the following code in the root .htaccess file to redirect the HTTP to HTTPS URL.

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

Here, we have discussed the most used rewrite rules and redirect URLs using HTACCESS. If you need any help regarding the .htaccess file, feel free to post your comment below.

Comments