diff --git a/lib/yrewrite/path_generator.php b/lib/yrewrite/path_generator.php index 428b52c..a2a50dd 100644 --- a/lib/yrewrite/path_generator.php +++ b/lib/yrewrite/path_generator.php @@ -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]); diff --git a/lib/yrewrite/yrewrite.php b/lib/yrewrite/yrewrite.php index 9c55cfb..219f60a 100644 --- a/lib/yrewrite/yrewrite.php +++ b/lib/yrewrite/yrewrite.php @@ -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); } } @@ -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)