• marketing@dgsol.co.uk
  • Address DGSOL CREATIVE LTD. 51 Solway Street West, Liverpool, England, L8 0TY, England
DGSOL Creative Ltd
Call Anytime
Redirect Http_ __ To Https_ In PHP

Redirect Http_ __ To Https_ In PHP

Many people who need to redirect from HTTP: // to HTTPS: // probably have encountered some problems when config .htaccess. Because now HTTPS: // has become the standard that affects SEO as well, let’s take a look at how PHP Redirection is done.

Let’s Start With A Simple Method.

Just create an index.php file and put the code below at the top of the page.


if (!(isset($_SERVER[‘HTTPS’]) && ($_SERVER[‘HTTPS’] == ‘on’ ||

$_SERVER[‘HTTPS’] == 1) ||




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

header(‘HTTP/1.1 301 Moved Permanently’);

header(‘Location: ‘ . $redirect);




Continue by uploading it to Public_html.

This is done ^ ^

The result when we redirect with PHP is that every time a Web Page is called via HTTP: //, the web page will be redirected to a URL that is encoded like HTTPS: //.