Create Top-Level 404 Page for a Multilingual Hugo Site

If you build a multilangual Hugo site, you may want to enable defaultContentLanguageInSubdir to make URLs look consistent. For example:

  • /en/post/an-english-post
  • /cn/post/a-chinese-post

As of Hugo v0.120.4, defaultContentLanguageInSubdir = "true" still has the side effect that no 404 page (404.html) is generated at the root of public directory, which causes Cloudflare Pages to redirect non-exstent pages to root /. 404.html at the root is needed to fix the problem.

There are three workarounds: reuse 404.html in a subdirectory, create, and create custom 404.html in static directory.