Skip to content

Commit

Permalink
improve detection of main domain behind a proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
norbertlaposa committed Nov 22, 2023
1 parent 22ec8de commit b9d8e1e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions controllers/uri_mapping.php
Expand Up @@ -290,14 +290,18 @@ static function checkForSecurityRedirects() {
*/

if (defined('ONYX_MAIN_DOMAIN') && strlen(ONYX_MAIN_DOMAIN) > 0) {
if (array_key_exists('HTTPS', $_SERVER)) $protocol = 'https';
if (array_key_exists('HTTPS', $_SERVER) || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $protocol = 'https';
else $protocol = 'http';

if ($_SERVER['HTTP_HOST'] != ONYX_MAIN_DOMAIN) {
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: $protocol://" . ONYX_MAIN_DOMAIN . "{$_SERVER['REQUEST_URI']}" );
//exit the application immediately
exit;
// server itself isn't running on main domain
if ($_SERVER['HTTP_HOST'] != ONYX_MAIN_DOMAIN && $_SERVER['HTTP_X_FORWARDED_HOST'] != ONYX_MAIN_DOMAIN) {
// it's not behind a proxy
if ($_SERVER['HTTP_X_FORWARDED_HOST'] != ONYX_MAIN_DOMAIN) {
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: $protocol://" . ONYX_MAIN_DOMAIN . "{$_SERVER['REQUEST_URI']}" );
//exit the application immediately
exit;
}
}
}

Expand Down

0 comments on commit b9d8e1e

Please sign in to comment.