Codeigniter Redirect HTTP Urls to HTTPS

Codeigniter Redirect HTTP Urls to HTTPS– There are many to redirect from http to https. Here in this tutorial, we are going to tell you the optimized way to redirect the http urls to https urls.

Codiegniter Redirect HTTP Urls to HTTPS

Codeigniter Redirect HTTP Urls to HTTPS

Add the below code to index.php, After adding the below code all http urls will be redirected to https.

$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
 if (strpos($url, 'http://') !== false) {
    $finalUrl = str_replace("http://","https://", $url);
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: $finalUrl"); 
    exit();
}

Advertisements

Add Comment

📖 Read More