Skip to content

Commit

Permalink
Improve support for regex redirects with query and params #1983
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 18, 2018
1 parent a49f3d4 commit 3091a14
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
## 04/12/2018

1. [](#new)
* added a new `Medium:thumbnailExists()` function [#1966](https://github.com/getgrav/grav/issues/1966)
* Added a new `Medium:thumbnailExists()` function [#1966](https://github.com/getgrav/grav/issues/1966)
1. [](#bugfix)
* fixed an issue with `custom_base_url` always causing 404 errors
* Fixed an issue with `custom_base_url` always causing 404 errors
* Improve support for regex redirects with query and params [#1983](https://github.com/getgrav/grav/issues/1983)

# v1.4.3
## 04/12/2018
Expand Down
11 changes: 5 additions & 6 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,13 @@ public function dispatch($route, $all = false, $redirect = true)
if ($site_route) {
$page = $this->dispatch($site_route, $all);
} else {
// Try Regex style redirects

/** @var Uri $uri */
$uri = $this->grav['uri'];
$source_url = $route;
$extension = $uri->extension();
if (isset($extension) && !Utils::endsWith($uri->url(), $extension)) {
$source_url.= '.' . $extension;
}
/** @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) {
Expand Down
17 changes: 17 additions & 0 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,23 @@ public function basename()
return $this->basename;
}

/**
* Return the full uri
*
* @param bool $include_root
* @return mixed
*/
public function uri($include_root = true)
{
if ($include_root) {
return $this->uri;
} else {
$uri = str_replace($this->root_path, '', $this->uri);
return $uri;
}

}

/**
* Return the base of the URI
*
Expand Down

0 comments on commit 3091a14

Please sign in to comment.