From e02016c5fe15cb428dde193a71906c85468c095f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 25 Feb 2026 11:42:35 +0100 Subject: [PATCH] layouts: add custom alias template that preserves query strings and anchors Hugo's built-in alias pages use a bare tag, which discards any query string or URL fragment from the original request. This is a problem when external links point to specific anchors on pages that have since been renamed. Adopt the custom alias.html layout from git-scm.com, which enhances the redirect with JavaScript that appends window.location.search and window.location.hash to the redirect target. The remains as a fallback for browsers with JavaScript disabled (which will still lose query strings and anchors, but at least land on the right page). Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- layouts/alias.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 layouts/alias.html diff --git a/layouts/alias.html b/layouts/alias.html new file mode 100644 index 0000000..b81649d --- /dev/null +++ b/layouts/alias.html @@ -0,0 +1,15 @@ +{{ $redirect_to := replaceRE `\.html$` "" (replace .Permalink "?" "%3F") }} + + + + Redirecting… + + + + + + +

Redirecting…

+ Click here if you are not redirected. + +