From 9ca411aa246efda8a139f11935bafd0ad01c1623 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 16 Jan 2019 17:05:42 -0700 Subject: [PATCH] Fixed issue with `redirect_trailing_slash` losing query string #2269 --- .../Common/Processors/InitializeProcessor.php | 8 +++++-- system/src/Grav/Framework/Route/Route.php | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Processors/InitializeProcessor.php b/system/src/Grav/Common/Processors/InitializeProcessor.php index d0e732653..d94bfc96c 100644 --- a/system/src/Grav/Common/Processors/InitializeProcessor.php +++ b/system/src/Grav/Common/Processors/InitializeProcessor.php @@ -53,8 +53,12 @@ class InitializeProcessor extends ProcessorBase // Redirect pages with trailing slash if configured to do so. $path = $uri->path() ?: '/'; - if ($path !== '/' && $config->get('system.pages.redirect_trailing_slash', false) && Utils::endsWith($path, '/')) { - $this->container->redirectLangSafe(rtrim($path, '/')); + if ($path !== '/' + && $config->get('system.pages.redirect_trailing_slash', false) + && Utils::endsWith($path, '/')) { + + $redirect = (string) $uri->getCurrentRoute()->withRoot(''); + $this->container->redirectLangSafe($redirect); } $this->container->setLocale(); diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php index b8abc72ef..b79938ea6 100644 --- a/system/src/Grav/Framework/Route/Route.php +++ b/system/src/Grav/Framework/Route/Route.php @@ -184,6 +184,30 @@ class Route return $this->queryParams[$param] ?? null; } + /** + * Allow the ability to set the route to something else + * + * @param $route + * @return $this + */ + public function withRoute($route) + { + $this->route = $route; + return $this; + } + + /** + * Allow the ability to set the root to something else + * + * @param $root + * @return $this + */ + public function withRoot($root) + { + $this->root = $root; + return $this; + } + /** * @param string $path * @return Route