How to redirect your website from HTTP to HTTPS ?

We are going to explain two ways to enable HTTP to HTTPS redirect:

Using .htaccess file:

Create or modify the .htaccess file located at the folder you want to redirect and add:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Using PHP:

You may use this code at the beginning of the PHP files you want to redirect:

 <?php
    function redirectTohttps() {
    if($_SERVER[‘HTTPS’]!=”on”) {
    $redirect= “https://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
    header(“Location:$redirect”);
             }
     }
?>
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

VPS Server Management from Clients Panel

For Customers to access their New VPS service, they need to do the following:Click on Services...

WHM/cPanel Log files

cPanel logs most activity tdat happens on a server to log files so you can go back and review log...

How to recompile Apache/PHP in WHM

Log into WHM and navigate to EasyApache (Apache Update)On the main page make sure ‘Begin by...

How To Fix "headers already sent" PHP Errors

Sometimes you my see an issue loading your site ( sometimes a 500 error ) and when you look into...

WHM asking to log in repeatedly when using CloudFlare

If you use CloudFlare to accelerate and protect the domain that you and your customers use to...