Last active
April 24, 2017 00:51
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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