From 5a9477a4025f4fb22608fd4945e71d45f7314d82 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 9 Feb 2021 21:23:23 +0200 Subject: [PATCH] Only redirect GET/HEAD if `system.pages.redirect_trailing_slash` is true and request has a trailing slash --- CHANGELOG.md | 1 + system/src/Grav/Common/Processors/InitializeProcessor.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17120547d..c46c090fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ * Fixed renaming flex objects key when using file storage * Fixed wrong values in Admin pages list [#3214](https://github.com/getgrav/grav/issues/3214) * Fixed pipelined asset using different hash when extra asset is added to before/after position [#2781](https://github.com/getgrav/grav/issues/2781) + * Only redirect GET/HEAD if `system.pages.redirect_trailing_slash` is true and request has a trailing slash # v1.7.5 ## 02/01/2021 diff --git a/system/src/Grav/Common/Processors/InitializeProcessor.php b/system/src/Grav/Common/Processors/InitializeProcessor.php index efdde5c8d..924dc29ca 100644 --- a/system/src/Grav/Common/Processors/InitializeProcessor.php +++ b/system/src/Grav/Common/Processors/InitializeProcessor.php @@ -30,6 +30,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function defined; +use function in_array; /** * Class InitializeProcessor @@ -414,6 +415,10 @@ class InitializeProcessor extends ProcessorBase protected function handleRedirectRequest(RequestInterface $request): ?ResponseInterface { + if (!in_array($request->getMethod(), ['GET', 'HEAD'])) { + return null; + } + // Redirect pages with trailing slash if configured to do so. $uri = $request->getUri(); $path = $uri->getPath() ?: '/';