diff --git a/include/site.inc b/include/site.inc index aae24537a6..2f48c491ea 100644 --- a/include/site.inc +++ b/include/site.inc @@ -233,24 +233,14 @@ function get_shortname($page) { return $shorturl; } -// Guess the current site from what Apache tells us. -// This should be the main name of the mirror (in case -// it works under more then one name). SERVER_NAME is -// the name of the Apache vhost. - -if (!isset($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != "on") { - $proto = "http"; -} else { - $proto = "https"; -} +// Build the base URL for the current site using the +// request scheme (HTTP/HTTPS) and the Host header. -if ($_SERVER["SERVER_PORT"] != '80' && $_SERVER["SERVER_PORT"] != 443) { - $MYSITE = $proto . '://' . $_SERVER["SERVER_NAME"] . ':' . (int)$_SERVER["SERVER_PORT"] . '/'; - $msite = 'http://' . $_SERVER["SERVER_NAME"] . ':' . (int)$_SERVER["SERVER_PORT"] . '/'; -} else { - $MYSITE = $proto . '://' . $_SERVER["SERVER_NAME"] . '/'; - $msite = 'https://' . $_SERVER["SERVER_NAME"] . '/'; -} +$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') + ? 'https' + : 'http'; + +$MYSITE = $scheme . '://' . $_SERVER['HTTP_HOST'] . '/'; // If the mirror is not registered with this name, provide defaults // (no country code, no search, no stats, English default language ...)