Your Location is: Home > Http-status-code-404

rust/mdBook: 404 page displays without CSS if the address is a subfolder

From: Mali View: 3291 Simon Bonsoir 


Using mdBook for a documentation website, I have a displaying error when the 404 page is in a subfolder.

Example: -> 404 page without CSS (subfolder in address) -> 404 page with CSS (no subfolder in address)

It's as if the {{ path_to_root }} variable wasn't taken into account in index.hbs when displaying a 404 page, but only when the address has one or several subfolders in it. Any idea on how to resolve this?

I realized also that {{ path_to_root }} variable was not processed in .md files, only in index.hbs.

Thank you for your help

Best answer

Here is a partial answer:

index.hbs must have the base_url set in order to default the 404 page at \ (making it works even if the wrong address is in a subfolder).

This must be included in index.hbs:

{{#if base_url}}
<base href="{{ base_url }}">

This resolves the 404 displaying problem.


However, this doesn't answer the question about {{ path_to_root }} not being rendered in .md files.

Don't hesitate to add details if needed.