Skip to content

Commit

Permalink
Fixed issue with site redirects/routes not processing with extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Oct 24, 2016
1 parent fb1c8eb commit afc1823
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
14 changes: 10 additions & 4 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit afc1823

Please sign in to comment.