From af62c3ede0a99574779997aa3c941868133da5ae Mon Sep 17 00:00:00 2001 From: randoum Date: Mon, 12 Oct 2020 11:38:51 +0200 Subject: [PATCH] Sub-page redirect with code fails Having a redirect set-up with a 3xx code ``` redirects: '/old_path': '/new_path[301]' ``` And accessing *http://my.site/old_path* the response is a *301* to *http://my.site/new_path*, as expected But when accessing *http://my.site/old_path/sub-page* the response is a *302* to *http://my.site/new_path[301]/sub-page*, which in turn respond another *302* to *http://my.site/new_path[301]/new_path[301]/sub-page* and so on and so forth until "TooManyRedirect" error is raised by the client. This PR intend to fix it and provide the following behavior : when accessing *http://my.site/old_path/sub-page* the response is a *301* to *http://my.site/new_path/sub-page* --- system/src/Grav/Common/Grav.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 458fe16c6f..59e19d9db2 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -320,7 +320,7 @@ public function redirect($route, $code = null) $route = preg_replace("#^\/[\\\/]+\/#", '/', $route); // Check for code in route - $regex = '/.*(\[(30[1-7])\])$/'; + $regex = '/.*(\[(30[1-7])\]).*/'; preg_match($regex, $route, $matches); if ($matches) { $route = str_replace($matches[1], '', $matches[0]);