From 3099f8e27e49e3d14b02719d088090900db1a9ce Mon Sep 17 00:00:00 2001 From: Skymirrh Date: Sat, 12 Sep 2020 20:37:49 +0200 Subject: [PATCH] Fix multilang redirects and routes Multilang redirects and routes were not working due to language prefixes being included in URL when trying to match source URL and redirect/route source pattern. Using `$route` parameter fixes the issue as given route does not include language prefixes (coming from `$uri->path()` in `PagesServiceProvider`). Fixes #2435. --- system/src/Grav/Common/Page/Pages.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 8f31afb09..97d455fc3 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -533,20 +533,14 @@ public function dispatch($route, $all = false, $redirect = true) if ($site_route) { $page = $this->dispatch($site_route, $all); } else { - - /** @var Uri $uri */ - $uri = $this->grav['uri']; - /** @var \Grav\Framework\Uri\Uri $source_url */ - $source_url = $uri->uri(false); - // Try Regex style redirects $site_redirects = $config->get('site.redirects'); if (is_array($site_redirects)) { foreach ((array)$site_redirects as $pattern => $replace) { $pattern = '#^' . str_replace('/', '\/', ltrim($pattern, '^')) . '#'; try { - $found = preg_replace($pattern, $replace, $source_url); - if ($found !== $source_url) { + $found = preg_replace($pattern, $replace, $route); + if ($found !== $route) { $this->grav->redirectLangSafe($found); } } catch (ErrorException $e) { @@ -561,8 +555,8 @@ public function dispatch($route, $all = false, $redirect = true) foreach ((array)$site_routes as $pattern => $replace) { $pattern = '#^' . str_replace('/', '\/', ltrim($pattern, '^')) . '#'; try { - $found = preg_replace($pattern, $replace, $source_url); - if ($found !== $source_url) { + $found = preg_replace($pattern, $replace, $route); + if ($found !== $route) { $page = $this->dispatch($found, $all); } } catch (ErrorException $e) {