Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/yrewrite/path_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ private function setPath(rex_article $article, rex_yrewrite_domain $domain, stri
}

if ($redirection instanceof rex_structure_element) {
[$_articleId, $hash] = array_pad(explode('#', $article->getValue('yrewrite_redirection'), 2), 2, null);
$this->redirections[$domainName][$articleId][$clangId] = [
'id' => $redirection->getId(),
'clang' => $redirection->getClangId(),
'path' => $url,
'hash' => $hash,
];

unset($this->paths[$domainName][$articleId][$clangId]);
Expand Down
16 changes: 15 additions & 1 deletion lib/yrewrite/yrewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public static function rewrite($params = [], $yparams = [], $fullpath = false)
if (isset($redirections[$id][$clang])) {
$params['id'] = $redirections[$id][$clang]['id'];
$params['clang'] = $redirections[$id][$clang]['clang'];
$params['hash'] = $redirections[$id][$clang]['hash'];
return self::rewrite($params, $yparams, $fullpath);
}
}
Expand Down Expand Up @@ -298,7 +299,20 @@ public static function rewrite($params = [], $yparams = [], $fullpath = false)
$urlparams = rex_string::buildQuery($params['params'], $params['separator']);
}

return $path . ($urlparams ? '?' . $urlparams : '');
// check if we already have a hash in $path
$hashFragment = parse_url($path, PHP_URL_FRAGMENT);
if ($hashFragment) {
if (isset($params['hash'])) {
// override hash from params
$path = str_replace('#' . $hashFragment, '#' . $params['hash'], $path);
} else {
// use hash from path
$path = str_replace('#' . $hashFragment, '', $path);
$params['hash'] = $hashFragment;
}
}

return $path . ($urlparams ? '?' . $urlparams : '') . (isset($params['hash']) ? '#' . $params['hash'] : '');
}

public static function rewriteMedia(array $params)
Expand Down