We published a guide showing how to force HTTPS using the Apache .htaccess configuration file. That is a system that works but is restricted to those using Apache as a web server. In today’s guide, we will show you how to use PHP to redirect HTTP to HTTPS.
The PHP solution provided here will work with different web A server is a computer application program that responds to requests for information from a client in a client/server relationship system. A typical example is a web server or pushing a web page to a web browser or a web server receiving email and transferring it to an email client. A server can also refer to the actual hardware designed... More including the mainstream one such as Apache, Nginx, and IIS.
Like all redirects, bad configurations can cause endless redirect loop errors. This involves checking if
$_SERVER['HTTPS'] variables exist or checking for a specific value of those variables.
The Working PHP Redirect HTTP to HTTPS Code
There you have it, that is how you can use PHP to redirect HTTP to HTTPS.