If you build a multilangual Hugo site, you may want to enable
defaultContentLanguageInSubdir to make URLs look consistent. For example:
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
404.md, and create custom
404.html in each subdirectory. Copy an
public directory after building.
hugo && cp public/en/404.html public works for Cloudflare Pages, Netlify and Vercel.
Don’t copy generated
static directory. When
404.html changes, you need to delete
404.html, build the site and copy
404.html. It’s annoying to repeat these steps.
404.md in a subdirectory, such as
Create custom 404.html
static directory. It’s copied to
public directory during building.
A minimal example:
A more complicated example: