Fix 404 page broken assets on deep URLs with base tag#455
Open
vittorio88 wants to merge 1 commit intodevcows:masterfrom
Open
Fix 404 page broken assets on deep URLs with base tag#455vittorio88 wants to merge 1 commit intodevcows:masterfrom
vittorio88 wants to merge 1 commit intodevcows:masterfrom
Conversation
Add <base href> tag to 404.html so relative URLs resolve correctly. Without it, when a user hits a deep non-existent path like /blog/2025/12/10/nonexistent/, the browser resolves all relative CSS, JS, and image URLs against that path, breaking the page layout. Also change the home button from relURL to absURL for consistency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<base href="{{ .Site.BaseURL }}">to404.html<head>relURLtoabsURLProblem
When a user hits a deep non-existent path like
/blog/2025/12/10/nonexistent/, the 404 page is served from that path. Without a<base>tag, the browser resolves all relative URLs (CSS, JS, images, nav links) against that deep path — breaking the entire page layout.This is the root cause behind issues like #141 (wrong URLs with double slashes) and #330 (404 on fresh install), where relative URL resolution fails depending on the serving path.
Fix
The
<base>tag tells the browser to resolve all relative URLs against the site's base URL instead of the current path. This is the standard HTML solution for pages served from unpredictable paths.Test plan
hugo serverand navigate to a deep non-existent URL (e.g.,/some/deep/fake/path/)🤖 Generated with Claude Code