diff options
| author | 2022-02-04 15:41:20 +0100 | |
|---|---|---|
| committer | 2022-02-04 15:41:20 +0100 | |
| commit | 88b934da8bec70da1400525748336c0b71864b1a (patch) | |
| tree | f5396060578dc05f6f0aee206387b479db2dccb7 | |
| parent | 60d96652dda458aeae78fd25f7c5f6818d518ef1 (diff) | |
Fix root redirection (#4167)
* Fix root redirection
#fix https://github.com/FreshRSS/FreshRSS/issues/4126
* Smarter
| -rw-r--r-- | lib/Minz/Request.php | 17 | ||||
| -rw-r--r-- | lib/Minz/Url.php | 2 | ||||
| -rw-r--r-- | p/index.php | 6 |
3 files changed, 15 insertions, 10 deletions
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index ee3962615..d67e23fdf 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -147,9 +147,9 @@ class Minz_Request { /** * Try to guess the base URL from $_SERVER information * - * @return string base url (e.g. http://example.com/) + * @return string base url (e.g. http://example.com) */ - public static function guessBaseUrl() { + public static function guessBaseUrl(): string { $protocol = self::extractProtocol(); $host = self::extractHost(); $port = self::extractPortForUrl(); @@ -225,12 +225,11 @@ class Minz_Request { return ''; } - /** - * @return string - */ - private static function extractPath() { - if ('' != $path = ($_SERVER['REQUEST_URI'] ?? '')) { - return '/' === substr($path, -1) ? substr($path, 0, -1) : dirname($path); + private static function extractPath(): string { + $path = $_SERVER['REQUEST_URI'] ?? ''; + if ($path != '') { + $path = parse_url($path, PHP_URL_PATH); + return substr($path, -1) === '/' ? rtrim($path, '/') : dirname($path); } return ''; } @@ -343,7 +342,7 @@ class Minz_Request { $url['params']['rid'] = self::requestId(); if ($redirect) { - header('Location: ' . Minz_Url::display($url, 'php')); + header('Location: ' . Minz_Url::display($url, 'php', 'root')); exit(); } else { self::_controllerName($url['c']); diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php index 06390c4c6..be3184b40 100644 --- a/lib/Minz/Url.php +++ b/lib/Minz/Url.php @@ -28,7 +28,7 @@ class Minz_Url { $url_string = Minz_Request::getBaseUrl(); if (strlen($url_string) < strlen('http://a.bc')) { $url_string = Minz_Request::guessBaseUrl(); - if (PUBLIC_RELATIVE === '..') { + if (PUBLIC_RELATIVE === '..' && preg_match('%' . PUBLIC_TO_INDEX_PATH . '(/|$)%', $url_string)) { //TODO: Implement proper resolver of relative parts such as /test/./../ $url_string = dirname($url_string); } diff --git a/p/index.php b/p/index.php new file mode 100644 index 000000000..65d3a8c3f --- /dev/null +++ b/p/index.php @@ -0,0 +1,6 @@ +<?php +require(__DIR__ . '/../constants.php'); +require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader + +FreshRSS_Context::initSystem(); +Minz_Request::forward(['c' => 'index', 'a' => 'index'], true); |
