Skip to content

Commit

Permalink
Merge pull request #759 from getgrav/feature/fix-redirect
Browse files Browse the repository at this point in the history
Add params, query and fragment when redirecting to a language or default route
  • Loading branch information
rhukster committed Apr 6, 2016
2 parents 9d2ef02 + 7619d3b commit 33d69d7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,35 @@ protected static function load(array $values)

// Redirection tests
if ($page) {
$url = $page->route();

if ($uri->params()) {
if ($url == '/') { //Avoid double slash
$url = $uri->params();
} else {
$url .= $uri->params();
}
}
if ($uri->query()) {
$url .= '?' . $uri->query();
}
if ($uri->fragment()) {
$url .= '#' . $uri->fragment();
}

// Language-specific redirection scenarios
if ($language->enabled()) {
if ($language->isLanguageInUrl() && !$language->isIncludeDefaultLanguage()) {
$c->redirect($page->route());
$c->redirect($url);
}
if (!$language->isLanguageInUrl() && $language->isIncludeDefaultLanguage()) {
$c->redirectLangSafe($page->route());
$c->redirectLangSafe($url);
}
}

// Default route test and redirect
if ($c['config']->get('system.pages.redirect_default_route') && $page->route() != $path) {
$c->redirectLangSafe($page->route());
$c->redirectLangSafe($url);
}
}

Expand Down

0 comments on commit 33d69d7

Please sign in to comment.