Would be great: 404 pages should use root-relative or absolute asset paths

I recently discovered an issue with custom 404 pages.

Sitely exports the 404 page with relative asset paths, for example:

css/site.css
images/logo.png
href="./"

When the page is served via Apache’s ErrorDocument 404, for example after requesting

/section/missing-page

the browser tries to load the assets from

/wer/css/
/wer/images/

instead of the website root. As a result, the 404 page is displayed without CSS, fonts and images.

The current workaround is to manually add

<base href="https://example.com/">

to the exported 404.html, but this has to be repeated after every publish.

It would be great if Sitely could either:

  • export the 404 page with root-relative asset paths (e.g. /css/..., /images/...),
  • automatically include a suitable <base> tag,
  • or provide an option to use absolute/root-relative paths for the 404 page.

This would make custom 404 pages work correctly with standard Apache ErrorDocument configurations without any manual editing.

True. We actually go our of our way to make the entire website path-relaitve, to make it just work in a variety of configurations, making the website portable to:

  • www or no www
  • http or https
  • testing or moving a site in a different folder

but 404 pages are problematic if you use sub-folders.

The base href is a possible trick.

All this ties into server configuration (via .htaccess or web.config), something we have dodged over the years because of its complexity and potential of breaking websites. What’s compex specifically is not creating a configuration, but dealing with a pre-existing configuration and interpreting what it does, particularly with mod_rewrite, or setups that rely on the combination of different server settings.

We need to bite the bullet and support server configuration, and for 404 pages support a special 404 page type that has absolute paths, conditioned to having set the correct website address, which as a consequence would break the website portability.

1 Like