Fix for custom_base_url issues #1736

This commit is contained in:
Andy Miller
2017-11-07 17:50:06 -07:00
parent 36f9865c0b
commit 0bca1dcb48
2 changed files with 18 additions and 7 deletions

View File

@@ -5,6 +5,7 @@
* Added `Medium::copy()` method to create a copy of a medium object
* Added new `force_lowercase_urls` functionality on routes and slugs
1. [](#bugfix)
* Fixed several issues related to `system.custom_base_url` that were broken [#1736](https://github.com/getgrav/grav/issues/1736)
* Dynamically added pages via `Pages::addPage()` were not firing `onPageProcessed()` event causing forms not to be processed
* Fixed `Page::active()` and `Page::activeChild()` to work with UTF-8 characters in the URL [#1727](https://github.com/getgrav/grav/issues/1727)
* Fixed typo in `modular.yaml` causing media to be ignored [#1725](https://github.com/getgrav/grav/issues/1725)

View File

@@ -286,17 +286,26 @@ class Uri
$this->base .= ':' . (string)$this->port;
}
// Set some defaults
if ($grav['config']->get('system.custom_base_url')) {
$this->root_path = parse_url($grav['config']->get('system.custom_base_url'), PHP_URL_PATH);
$this->root = $grav['config']->get('system.custom_base_url');
// Handle custom base
$custom_base = rtrim($grav['config']->get('system.custom_base_url'), '/');
if ($custom_base) {
$custom_parts = parse_url($custom_base);
$orig_root_path = $this->root_path;
$this->root_path = isset($custom_parts['path']) ? rtrim($custom_parts['path'], '/') : '';
$this->root = isset($custom_parts['scheme']) ? $custom_base : $this->base . $this->root_path;
$this->uri = Utils::replaceFirstOccurrence($orig_root_path, $this->root_path, $this->uri);
// If custom_base_url has a domain, force absolute_urls to true
if (isset($custom_parts['scheme'])) {
$config->set('system.absolute_urls', true);
}
} else {
$this->root = $this->base . $this->root_path;
}
$this->url = $this->base . $this->uri;
// get any params and remove them
$uri = str_replace($this->root, '', $this->url);
// remove the setup.php based base if set:
@@ -306,8 +315,9 @@ class Uri
}
// If configured to, redirect trailing slash URI's with a 302 redirect
if ($uri !== '/' && $config->get('system.pages.redirect_trailing_slash', false) && Utils::endsWith($uri, '/')) {
$grav->redirect(str_replace($this->root, '', rtrim($uri, '/')), 302);
$redirect = Utils::replaceLastOccurrence($this->root, '', rtrim($uri, '/'));
if ($uri !== '/' && $redirect !== $this->base() && $config->get('system.pages.redirect_trailing_slash', false) && Utils::endsWith($uri, '/')) {
$grav->redirect($redirect, 302);
}
// process params