How do I properly use header function, so
header("location: http://".$_SERVER['HTTP_HOST']."/?para=abc"); //for http
and
header("location: https://".$_SERVER['HTTP_HOST']."/?para=abc"); //for https
could be written in 1 string if possible?
.htaccess file will take care of all http pages to be redirected to https with no problem, but I believe it makes sense to use a proper syntax for http/https pages in header("location:...)
, so it is correct for all browsers.
This should work for Apache, at least.
You can isolate the protocol-type by doing something like this:
Then
You could also use the following code:
You can get the protocol by following code:
and then redirect like this