Added a language-safe redirect option that appends lang if set

This commit is contained in:
Andy Miller
2015-07-08 11:23:51 -06:00
parent 939449c1b0
commit 60e183a8c0
2 changed files with 20 additions and 1 deletions

View File

@@ -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.
*

View File

@@ -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());