Skip to content

Relative Paths in Custom 404 Page Not Resolving Correctly for Non-Root URLs #194

Open
@zivmax

Description

@zivmax

When using Jekyll, the 404 page (defined with permalink: /404.html) does not correctly resolve relative paths for non-root URLs. This issue occurs because Jekyll infers the relative paths based on the URL being accessed, which causes styles, scripts, and other assets to fail to load when accessing non-existent pages at deeper URL levels.

Problem Description

For example:

  • Accessing a non-existent URL like <server>:<port>/non-exist renders the 404 page correctly, and all assets load as expected.
  • However, accessing a non-existent URL like <server>:<port>/non/exist causes the relative paths to be resolved incorrectly. The browser attempts to load assets from /non/assets/... instead of ../assets/... or /assets/..., resulting in the following errors:
[2025-01-22 12:32:51] ERROR '/non/exist' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/bootstrap-table/dist/bootstrap-table.min.css' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/bootstrap/dist/js/bootstrap.bundle.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/jquery/dist/jquery.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/@fortawesome/fontawesome-free/css/all.min.css' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/bootstrap-table/dist/extensions/mobile/bootstrap-table-mobile.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/bootstrap-table/dist/bootstrap-table.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/luxon/build/global/luxon.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/mathjax/es5/tex-chtml.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/vanilla-lazyload/dist/lazyload.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/intersection-observer/intersection-observer.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/iframe-resizer/js/iframeResizer.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/scratchblocks.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/twemoji/dist/twemoji.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/page.css' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/mermaid.min.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/jekyll-theme-cs50.js' not found.
[2025-01-22 12:32:51] ERROR '/non/assets/page.js' not found.
[2025-01-22 12:32:51] ERROR '/non/favicon.ico' not found.

Expected Behavior

The 404 page should resolve all relative paths (e.g., /assets/...) correctly, regardless of the URL being accessed. For example, accessing <server>:<port>/non/exist should load assets from /assets/... or ../assets/... instead of /non/assets/....

Steps to Reproduce

  1. Set up a Jekyll site with a 404 page defined using permalink: /404.html.
  2. Access a non-existent root-level URL (e.g., <server>:<port>/non-exist). The 404 page should render correctly.
  3. Access a non-existent deeper-level URL (e.g., <server>:<port>/non/exist). The 404 page will render, but assets will fail to load due to incorrect relative path resolution.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions