Skip to content

Instantly share code, notes, and snippets.

@geekwright

geekwright/scheme-301.php

Last active Apr 24, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.