Vojtěch Struhár

Posted on December 2, 2024 | #self-host

Astro 404 page with Apache

I recently had the privilege to host a static Astro website on a cPanel server. And since cPanel uses Apache by default, the custom 404 page can be configured by a single line of code.

  1. Create your 404 site - pages/404.astro. If you name it precisely this, Astro will route to it in dev mode!
  2. Create a public/.htaccess file. Apache will pick up on this config file automatically, it will just get copied to the server

Put this line into .htaccess

# Redirect all 404 errors
ErrorDocument 404 /404.html

Done, awesome. You could also redirect to your root if that makes sense for you.

Other approaches

I think compared to those, the .htaccess file way is a pure beauty.

Read next → Self host Plausible analytics