From afc18236c2d43907b96577272dff517ddc037640 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 24 Oct 2016 10:13:21 -0600 Subject: [PATCH] Fixed issue with site redirects/routes not processing with extensions --- CHANGELOG.md | 6 ++++++ system/src/Grav/Common/Page/Pages.php | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e44f6fbc..837f1b2a71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.1.9 +## xx/xx/2016 + +1. [](#bugfix) + * Fixed an issue with site redirects/routes, not processing with extension (.html, .json, etc.) + # v1.1.8 ## 10/22/2016 diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 719f48937f..0b7691b4a7 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -342,13 +342,19 @@ public function dispatch($url, $all = false, $redirect = true) $page = $this->dispatch($route, $all); } else { // Try Regex style redirects + $source_url = $url; + $extension = $this->grav['uri']->extension(); + if (isset($extension)) { + $source_url.= '.' . $extension; + } + $site_redirects = $config->get("site.redirects"); if (is_array($site_redirects)) { foreach ((array)$site_redirects as $pattern => $replace) { $pattern = '#' . $pattern . '#'; try { - $found = preg_replace($pattern, $replace, $url); - if ($found != $url) { + $found = preg_replace($pattern, $replace, $source_url); + if ($found != $source_url) { $this->grav->redirectLangSafe($found); } } catch (ErrorException $e) { @@ -363,8 +369,8 @@ public function dispatch($url, $all = false, $redirect = true) foreach ((array)$site_routes as $pattern => $replace) { $pattern = '#' . $pattern . '#'; try { - $found = preg_replace($pattern, $replace, $url); - if ($found != $url) { + $found = preg_replace($pattern, $replace, $source_url); + if ($found != $source_url) { $page = $this->dispatch($found, $all); } } catch (ErrorException $e) {