Skip to content

Commit

Permalink
alternative way for language filter redirects (as discussed in 11196)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepereiradasilva committed Jul 19, 2016
1 parent df34366 commit 38b92ae
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,36 @@ public function parseRule(&$router, &$uri)
$uri->setPath('index.php/' . $uri->getPath());
}

$this->app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')), 301);
$redirectUri = $uri->base() . $uri->toString(array('path', 'query', 'fragment'));
}
else
{
$uri->setVar('lang', $this->lang_codes[$lang_code]->sef);
$this->app->redirect($uri->base() . 'index.php?' . $uri->getQuery(), 301);
$redirectUri = $uri->base() . 'index.php?' . $uri->getQuery();
}

// Set redirect HTTP code to "302 Found".
$redirectHttpCode = 302;

// If selected language is the default language redirect code is "301 Moved Permanently".
if ($lang_code === $this->default_lang)
{
$redirectHttpCode = 301;

// If configured to always use a sef prefix for default language we cannot cache this redirect in browser.
// 301 is cachable by default so we need to force to not cache it in browsers.
if ((int) $this->params->get('remove_default_prefix', 0) === 0)
{
$this->app->setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00 GMT', true);
$this->app->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
$this->app->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false);
$this->app->setHeader('Pragma', 'no-cache');
$this->app->sendHeaders();
}
}

// Redirect to language.
$this->app->redirect($redirectUri, $redirectHttpCode);
}

// We have found our language and now need to set the cookie and the language value in our system
Expand Down

0 comments on commit 38b92ae

Please sign in to comment.