Fix 404 Error When Pushing Hugo to a Github Repository that Points to a Custom Domain
The Problem
You once experienced the joy of seeing your Hugo site up on github pages pointing to a custom url. Then you decided to push new pages to the repo and your custom domain is a 404 page! What’s happening??
The Solution
When you update your repository’s Github Pages settings to point to a custom domain, Github creates a file CNAME
inside your directory /docs
. You may have accidentally overwrote this file when you did your last git push
! To solve this:
- Create the file
CNAME
inside a/static
folder (which can be created in root and/or in your THEME folder) - Add your domain inside that file in the format “domain.com”. Don’t add “https://” before it!.
- Wait a few minutes and then notice that your site is (hopefully) working again! If it’s not, consider reading our guide Loading Hugo into Github Pages.