diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-09-03 14:51:41 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-09-12 21:39:01 +0200 |
commit | 650a5f09cbeb1c1bef19810c6cc504c06d5b7e87 (patch) | |
tree | 6be70f1658128246e57d39c73e1bc3b13e992de1 /application/http/HttpUtils.php | |
parent | e809908f9e593b2cec11f72849caa1dae6394451 (diff) | |
download | Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.tar.gz Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.tar.zst Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.zip |
Add manual configuration for root URL
This new setting under 'general.root_url' allows to override automatic discovery of Shaarli instance's URL.
Fixes #1339
Diffstat (limited to 'application/http/HttpUtils.php')
-rw-r--r-- | application/http/HttpUtils.php | 8 |
1 files changed, 6 insertions, 2 deletions
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) | |||
369 | */ | 369 | */ |
370 | function index_url($server) | 370 | function index_url($server) |
371 | { | 371 | { |
372 | $scriptname = $server['SCRIPT_NAME'] ?? ''; | 372 | if (defined('SHAARLI_ROOT_URL') && null !== SHAARLI_ROOT_URL) { |
373 | return rtrim(SHAARLI_ROOT_URL, '/') . '/'; | ||
374 | } | ||
375 | |||
376 | $scriptname = !empty($server['SCRIPT_NAME']) ? $server['SCRIPT_NAME'] : '/'; | ||
373 | if (endsWith($scriptname, 'index.php')) { | 377 | if (endsWith($scriptname, 'index.php')) { |
374 | $scriptname = substr($scriptname, 0, -9); | 378 | $scriptname = substr($scriptname, 0, -9); |
375 | } | 379 | } |
@@ -392,7 +396,7 @@ function page_url($server) | |||
392 | $scriptname = substr($scriptname, 0, -9); | 396 | $scriptname = substr($scriptname, 0, -9); |
393 | } | 397 | } |
394 | 398 | ||
395 | $route = ltrim($server['REQUEST_URI'] ?? '', $scriptname); | 399 | $route = preg_replace('@^' . $scriptname . '@', '', $server['REQUEST_URI'] ?? ''); |
396 | if (! empty($server['QUERY_STRING'])) { | 400 | if (! empty($server['QUERY_STRING'])) { |
397 | return index_url($server) . $route . '?' . $server['QUERY_STRING']; | 401 | return index_url($server) . $route . '?' . $server['QUERY_STRING']; |
398 | } | 402 | } |