How To/HTTP to HTTPS redirect

From Roaring Penguin
Revision as of 14:43, 21 January 2015 by Admin (talk | contribs) (Ticket #38831)

Jump to: navigation, search

You can do that 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 ?>