Skip to content

Commit c8c6fb8

Browse files
authored
Merge pull request #2124 from ogumemura/patch-2
Update config.inc.tpl
2 parents 252d3f9 + 8525c62 commit c8c6fb8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

install/config.inc.tpl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,19 @@ if (!empty($site_hostnames[0]) && !in_array($site_hostname, $site_hostnames)) {
131131
// assign site_url
132132
if (!defined('MODX_SITE_URL')) {
133133
$secured = (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
134+
$user_port = isset($_SERVER['HTTP_X_FORWARDED_PORT']) ? $_SERVER['HTTP_X_FORWARDED_PORT'] : $_SERVER['SERVER_PORT']; // Store the port number used by users to connect to the site on the front-end
134135
// $site_url = ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port || $secured) ? 'https://' : 'http://';
135-
$site_url = ((isset ($_SERVER['HTTPS']) && ( (strtolower($_SERVER['HTTPS']) == 'on') || ($_SERVER['HTTPS']) == '1')) || $_SERVER['SERVER_PORT'] == $https_port || $secured) ? 'https://' : 'http://';
136+
// $site_url = ((isset ($_SERVER['HTTPS']) && ( (strtolower($_SERVER['HTTPS']) == 'on') || ($_SERVER['HTTPS']) == '1')) || $_SERVER['SERVER_PORT'] == $https_port || $secured) ? 'https://' : 'http://';
137+
// Replace any occurrence of $_SERVER['SERVER_PORT'] with $user_port from now on
138+
$site_url = ((isset ($_SERVER['HTTPS']) && ( (strtolower($_SERVER['HTTPS']) == 'on') || ($_SERVER['HTTPS']) == '1')) || $user_port == $https_port || $secured) ? 'https://' : 'http://';
136139
137140
$site_url .= $site_hostname;
138-
if ($_SERVER['SERVER_PORT'] != 80) {
139-
$site_url = str_replace(':' . $_SERVER['SERVER_PORT'], '', $site_url);
140-
} // remove port from HTTP_HOST  
141+
if ($user_port != 80) {
142+
$site_url = str_replace(':' . $user_port, '', $site_url);
143+
} // remove port from HTTP_HOST
141144

142-
$site_url .= ($_SERVER['SERVER_PORT'] == 80 || (isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? '' : ':' . $_SERVER['SERVER_PORT'];
145+
// $site_url .= ($_SERVER['SERVER_PORT'] == 80 || (isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? '' : ':' . $_SERVER['SERVER_PORT'];
146+
$site_url .= ($user_port == 80 || (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $user_port == $https_port) ? '' : ':' . $user_port;
143147
$site_url .= $base_url;
144148

145149
define('MODX_SITE_URL', $site_url);

0 commit comments

Comments
 (0)