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.
 <?php
if (!(isset($_SERVER[‘HTTPS’]) && ($_SERVER[‘HTTPS’] == ‘on’ ||
$_SERVER[‘HTTPS’] == 1) ||
isset($_SERVER[‘HTTP_X_FORWARDED_PROTO’]) &&
$_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’))
{
$redirect = ‘https://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’];
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: ‘ . $redirect);
exit();
}
?>
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: //.