diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 127f8ab14..71810e23e 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -267,6 +267,25 @@ class Grav extends Container exit(); } + /** + * Redirect browser to another location taking language into account (preferred) + * + * @param string $route Internal route. + * @param int $code Redirection code (30x) + */ + public function redirectLangSafe($route, $code = 303) + { + /** @var Language $language */ + $language = $this['language']; + $config = $this['config']; + + if ($language->enabled()) { + return $this->redirect($language->getLanguage() . $route, $code); + } else { + return $this->redirect($route); + } + } + /** * Returns mime type for the file format. * diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index a998771cc..f2a81ae54 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -279,7 +279,7 @@ class Pages try { $found = preg_replace($pattern, $replace, $url); if ($found != $url) { - $this->grav->redirect($found); + $this->grav->redirectLangSafe($found); } } catch (ErrorException $e) { $this->grav['log']->error('site.redirects: '. $pattern . '-> ' . $e->getMessage());