How to Redirect a Website from http to https?

July 7, 2020 / Tutorial

You can follow any of the three methods mentioned below for redirecting your website from HTTP to HTTPS-

Method 1: Using a .htaccess file

You can use the following code and edit the .htaccessfile for moving from HTTP to HTTPS-

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Usually, the websites often use an HTTP protocol as the default protocol for handling all the critical information. Still, with https, you get various security and other benefits for your website.

Method 2: Using a PHP function

You can also use the following .php function for redirecting your website. You just need to call the function in the right place from where you wish to get the redirection.

< ?php

function redirectTohttps() {

if($_SERVER[‘HTTPS’]!=”on”) {

$redirect= “https://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];

header(“Location:$redirect”); } }


Method 3: Using an HTML Meta Tag

The methods discussed above are sufficient enough for making a move to HTTP from HTTPS. Using an HTML Tag might not be that effective as compared to the previous two. Still, you can use it if you fail to use the “mod rewrite.”

Make sure to add the following to your web page header-

< meta http-equiv=”Refresh” content=”0;URL=” />

Leave a Reply

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