Skip to content

Fix 404 page broken assets on deep URLs with base tag#455

Open
vittorio88 wants to merge 1 commit intodevcows:masterfrom
lagobello:fix/404-base-tag
Open

Fix 404 page broken assets on deep URLs with base tag#455
vittorio88 wants to merge 1 commit intodevcows:masterfrom
lagobello:fix/404-base-tag

Conversation

@vittorio88
Copy link
Contributor

@vittorio88 vittorio88 commented Mar 15, 2026

Summary

  • Adds <base href="{{ .Site.BaseURL }}"> to 404.html <head>
  • Changes the home button link from relURL to absURL

Problem

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

  • Run hugo server and navigate to a deep non-existent URL (e.g., /some/deep/fake/path/)
  • Verify the 404 page renders correctly with CSS, images, and navigation intact
  • Verify the "Go Home" button links to the site root

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant