diff --git a/src/Http/Request.php b/src/Http/Request.php index ea378c60..ee3bbe8d 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -193,7 +193,7 @@ public function path(): string */ public function decodedPath(): string { - return rawurldecode($this->path()); + return rawurldecode(trim($this->path(), '/')); } /** diff --git a/src/Http/ServerRequest.php b/src/Http/ServerRequest.php index a4641d58..b5f883e3 100644 --- a/src/Http/ServerRequest.php +++ b/src/Http/ServerRequest.php @@ -238,16 +238,18 @@ protected function _setConfig(array $config): void } elseif ($config['url'] !== '') { $config = $this->processUrlOption($config); $uri = new Uri(implode('?', [$config['url'], $config['environment']['QUERY_STRING'] ?? ''])); - } elseif (isset($config['environment']['REQUEST_URI'])) { - $uri = new Uri($config['environment']['REQUEST_URI']); } else { - $uri = Psr7ServerRequest::getUriFromGlobals(); + $uri = new Uri(Psr7ServerRequest::getUriFromGlobals()->__toString()); + } + + if (isset($config['environment']['REQUEST_URI'])) { + $uri = $uri->withPath($config['environment']['REQUEST_URI']); } if (in_array($uri->getHost(), ['localhost', '127.0.0.1'], true)) { $uri = $uri->withHost(parse_url(config('app.base_url'), PHP_URL_HOST)); } - + $this->_environment = $config['environment']; $this->uri = $uri;