Difference between revisions of "How To/HTTP to HTTPS redirect"
From Roaring Penguin
m |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
− | You can do | + | You can do this by making a file: |
/var/www/canit/site/config.d/0_redirect.php | /var/www/canit/site/config.d/0_redirect.php | ||
Line 8: | Line 8: | ||
# Redirect HTTP => HTTPS | # Redirect HTTP => HTTPS | ||
if (!array_key_exists('HTTPS', $_SERVER) || !$_SERVER['HTTPS']) { | if (!array_key_exists('HTTPS', $_SERVER) || !$_SERVER['HTTPS']) { | ||
− | if (empty($_SERVER['QUERY_STRING'])) | + | if (empty($_SERVER['QUERY_STRING'])) { |
header("Location: https://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']); | header("Location: https://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']); | ||
} else { | } else { |
Latest revision as of 10:53, 5 January 2017
You can do this by making a file:
/var/www/canit/site/config.d/0_redirect.php
with the following content;
<?php # Redirect HTTP => HTTPS if (!array_key_exists('HTTPS', $_SERVER) || !$_SERVER['HTTPS']) { if (empty($_SERVER['QUERY_STRING'])) { header("Location: https://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']); } else { header("Location: https://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']); } exit(); } ?>
Note: nothing before <? or after ?>