How to Set Up a Custom 404 Page With Hugo
Published: 2024-04-28 | Updated: 2024-05-16The problem
When I built this site using Hugo I didn’t give much thought to putting up a custom 404/Not Found error page. But after all the excitement of launching a new thing died down I discovered my site was snowing very ugly Apache error page when a 404/Not Found error occurred.
Here’s how I set up a custom 404/NotFound page for this site.
The Solution
First, create a 404.html page in your layouts folder. I simply copied my home.html - an easy choice because most, if not all 404 pages I’ve run accross link back to Home anyway. So why not?
Second and last, I needed to reconfigure and reload Apache.
- Spin up a SSH session:
ssh mark@myServer.me
sudo vim /etc/apache2/sites-available/tdstg.conf
or nano or whatever you fancy. Then- Inside the VirtualHost block, add this:
ErrorDocument 404 /404.html
- Do the same edit in the SSL version of your .conf file. Mine is named
tdstg-le-ssl.conf
- Lastly, reload Apache
sudo systemctl reload apache2
Done. Navigate to some non-existent URI on your site and behold the glory of your custom 404.html