Skip to content

Instantly share code, notes, and snippets.

@geekwright
Last active April 24, 2017 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekwright/5cc0b93b41b9515b3f06ad3d6b9dd772 to your computer and use it in GitHub Desktop.
Save geekwright/5cc0b93b41b9515b3f06ad3d6b9dd772 to your computer and use it in GitHub Desktop.
This code fragment is intended to be added into a XOOPS installation's mainfile.php. If the invoking URL does not match the scheme declared in XOOPS_URL (i.e. "https",) it will force a 301 redirect to the matching URL with the declared scheme.
<?php
// add these lines to mainfile.php directly below the line "define('XOOPS_URL', ...);"
$checkScheme = function () {
$s = $_SERVER;
$parsed = parse_url(XOOPS_URL);
$targetScheme = $parsed['scheme'];
$currentScheme = (!empty($s['HTTPS']) && $s['HTTPS'] !== 'off') ? 'https' : 'http';
if (0 !== strcmp($targetScheme, $currentScheme)) {
$host = $parsed['host'];
$port = isset($parsed['port']) ? ':' . $parsed['port'] : '';
$fullUrl = $targetScheme . '://' . $host . $port . $s['REQUEST_URI'];
header('Location: ' . $fullUrl, true, 301);
exit();
}
};
$checkScheme();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment