Adding 404 page to a custom path

Hi!

I would like to use a custom 404.html which is generated by Sphinx, but the file is not inserted on root level.

To be more specific, this file https://github.com/conan-io/docs/blob/gh-pages/en/latest/404.html should be used for default 404 error.

However, it does not, so I’ve added a default 404.html to redict: https://github.com/conan-io/docs/blob/gh-pages/404.html

Is there some way to do it, without that file on the root level? (I’m not using Jekyll).

Hi, @uilianries!

I’m afraid GitHub Pages only supports storing a custom 404 page in the root of your publishing source.

That said, rather than creating a unique HTML file at this location, and within it a JavaScript redirect, you could instead consider using a symlink.

By creating a symlink to en/latest/404.html, you can save yourself the hassle and inelegance of the redirect. Instead, GitHub Pages will simply follow the symlink during the build process, and implement your desired custom 404 page.

On macOS, Linux, or Git Bash, you can create the necessary symlink by running this command from the root of your repository’s gh-pages branch:

ln -s en/latest/404.html

I hope that helps!

Friday

2 Likes

Thanks a lot @darrowby385!

1 Like