LSurl::public_url: fix handling public root URL with a trailing slash

This commit is contained in:
Benjamin Renard 2024-09-26 14:50:47 +02:00
parent b195a266f4
commit 977dc8fcfa
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -192,13 +192,24 @@ class LSurl extends LSlog_staticLoggerClass {
$public_root_url = LSconfig :: get('public_root_url', '/', 'string');
if ($absolute && $public_root_url[0] == '/') {
self :: log_debug("LSurl :: public_root_url(absolute=true): configured public root URL is relative ($public_root_url) => try to detect it from current request infos.");
$public_root_url = 'http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'?'s':'').'://'.$_SERVER['HTTP_HOST'].$public_root_url;
self :: log_debug("LSurl :: public_root_url(absolute=true): detected public absolute root URL: $public_root_url");
self :: log_debug(
"LSurl :: public_root_url(absolute=true): configured public root URL is relative ".
"($public_root_url) => try to detect it from current request infos."
);
$public_root_url = sprintf(
"http%s://%s%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'?'s':'',
$_SERVER['HTTP_HOST'],
$public_root_url
);
self :: log_debug(
"LSurl :: public_root_url(absolute=true): detected public absolute root URL: ".
$public_root_url
);
}
if ($relative_url) {
if ($public_root_url[0] == '/') $public_root_url .= "/";
if ($public_root_url[-1] != '/') $public_root_url .= "/";
return $public_root_url.$relative_url;
}