404 Error page per language

To maintain content structure in my site, I decided to skip appending the language code to the translated content and have it point to the root domain, as the default content language does (e.g. example.com/eat/ and example.com/manger/). Only the homepage for the translated language has the language extension e,g, example.com/fr/. However, the 404 page in the publish directory points to the default language, even after translating the entries using the i18n folder. Is there a way to make sure the error page that shows when the language is switched is that of the same language?

Have you got set 404 per language?

layouts\404.html (default language)
layouts\404.de.html (German)

Then i18n will work correctly.

Yes, but as mentioned, since I am not using the language code in my URLs, Hugo builds the default language 404 in the root and the secondary one in the language folder. So, only the translated homepage uses the translated 404 file, and the rest defaults to the default file.

Could you post link to you site code as need to see how you got this structured then.

Here is a test site (it is not malicious, but scan before extracting). Just build with hugo command and check the results (404 in de folder and main one in root).

if you not using languages in filename try


There is a bit of confusion here as well.
All your posts got custom URL and server in /

Not like:

/post1 (in english)
/de/post1 (in german)

think in that instance your setup doesn’t know which 404 to serve, hence serving layout\404.html.

Other observations

DefaultContentLanguage = "en"

Add this to your config as described here Multilingual Mode | Hugo

apart from the menu switcher between languages, you don’t have any hreflang implemented, at least they are not advised in the meta tag.

This does not generate the files in the public folder. I think this might be a shortcoming of my own site structure, so it seems like an exercise in futility.

I mentioned that in the original post. I am translating an existing site, so I maintained the URL structure. I did not want to append the language in the URL except the homepage and I am so deep in translation I cannot go back now.

That is my test site, not main. The main one has all tags set (and a modified language switcher).

I decided to just append the language to the URL and then do a redirect. Luckily, most of my over 250 translated pages already begin with the same word in the URL after the root domain, so it was was easy to redirect them. The remaining ones I will redirect manually. Now the 404 is working.

remember to set aliases in fronmatter to have redirect and do not lose the power of original links. no need to do it manually.

url: "/de/your-new-fancy-url/"
 - "/your-old-powerfull-url/"

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.