UPDATE Apparently, this was only necessary for my site, when it was built with Hexo. I have migrated to Astro, which handles the routing for me now.
Often overlooked, yet helpful: it is nice-to-have a proper 404-page, of which some are humorous. All of them serve a better browsing experience, because that page tells the user that a requested resource (page) does not exist. Without a 404-page, the browser would just display a blank page, which is not helpful.
In order have offer this on the own website, there are two requirements:
- there must be a html-file that serves as 404-page
- the error-handling or routing of the web server must be configured, so requests for non-existent resources are properly handled, in this case: forwarded to the custom 404-page.
Updating your Caddyfile
The following text focuses on the second point, using Caddy as web server.
- Open your Caddyfile in an editor
- Add the
handle_errors
-snippet:
- Reload the configuration, e.g. via
sudo systemctl reload caddy
Additional resources
- Original source with Caddyfile configuration, I was using at first
- Official documentation on handle_errors. Check out the examples! Seeing this also makes me realise how unnecessary this post is. I am going to post this text nevertheless, as reference to my future self.
- Official documentation on rewrite directive
Edit
The following snippet is the configuration I had used until recently. Writing this article, I was about to use that snippet (see below). This time, I also checked out the referenced issue and realised that the official documentation now offers a much simpler and more flexible configuration.