Web Hosting

How to Redirect a Website from http to https?

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

Method 1: Using an .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 in your web page header-

< meta http-equiv=”Refresh” content=”0;URL=https://www.yourdomainname.com” />

Leave a Reply

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