mirror of
https://github.com/getgrav/grav.git
synced 2026-07-07 17:21:49 +02:00
Added a language-safe redirect option that appends lang if set
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user