X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fhttp%2FHttpUtils.php;h=9f4140735a695c4ab8e08b2c10a8e49eaa3527bb;hb=650a5f09cbeb1c1bef19810c6cc504c06d5b7e87;hp=4fc4e3dcff08f3457c7a2d541962c699979732c7;hpb=e809908f9e593b2cec11f72849caa1dae6394451;p=github%2Fshaarli%2FShaarli.git diff --git a/application/http/HttpUtils.php b/application/http/HttpUtils.php index 4fc4e3dc..9f414073 100644 --- a/application/http/HttpUtils.php +++ b/application/http/HttpUtils.php @@ -369,7 +369,11 @@ function server_url($server) */ function index_url($server) { - $scriptname = $server['SCRIPT_NAME'] ?? ''; + if (defined('SHAARLI_ROOT_URL') && null !== SHAARLI_ROOT_URL) { + return rtrim(SHAARLI_ROOT_URL, '/') . '/'; + } + + $scriptname = !empty($server['SCRIPT_NAME']) ? $server['SCRIPT_NAME'] : '/'; if (endsWith($scriptname, 'index.php')) { $scriptname = substr($scriptname, 0, -9); } @@ -392,7 +396,7 @@ function page_url($server) $scriptname = substr($scriptname, 0, -9); } - $route = ltrim($server['REQUEST_URI'] ?? '', $scriptname); + $route = preg_replace('@^' . $scriptname . '@', '', $server['REQUEST_URI'] ?? ''); if (! empty($server['QUERY_STRING'])) { return index_url($server) . $route . '?' . $server['QUERY_STRING']; }