ccihosting.com
Have questions? Call us.
Panama: (+507) 264.0852

HTTP to HTTPS redirect

CCIHosting.com knowledgebase

Knowledgebase

How to 301 redirect HTTP to HTTPS

In this article 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”);
             }
     }
?>

Need a Web Hosting account?

Web Hosting

$ 6/month
Starting at

View Plans

  • Instant Activation
  • DDoS Protection
  • 24x7 Tech Support
  • Bitcoin Accepted

VPS

$ 15/month
Starting at

View Plans

  • Instant Activation
  • DDoS Protection
  • 24x7 Tech Support
  • Bitcoin Accepted

Cloud Servers

$ 35/month
Starting at

View Plans

  • Instant Activation
  • DDoS Protection
  • 24x7 Tech Support
  • Bitcoin Accepted

Dedicated Servers

$ 90/month
Starting at

View Plans

  • 48 Hours or Less
  • DDoS Protection
  • 24x7 Tech Support
  • Bitcoin Accepted
paypal
visa
mastercard
bitcoin

Need assistance choosing your right server? We are here to help

Call our sales team at +(507) 264.0852 or talk with us on Live Chat