404 error for translated pages

  1. I created a new site (and theme) with Hugo.
  2. Then I configured language translation by filename (EN and DE). I then copied the post-1 file into a new page bundle and renamed it to index.md. I added url = "post-1" to the front matter.
  3. I then copied this file and renamed the copy to index.de.md. I changed the URL to url = "post-1-de". But opening this URL returns a 404
[languages]
  [languages.en]
    disabled = false
    languageCode = 'en-US'
    languageDirection = 'ltr'
    languageName = 'English'
    weight = 1
  [languages.de]
    disabled = false
    languageCode = 'de-DE'
    languageDirection = 'ltr'
    languageName = 'Deutsch'
    weight = 2
hugo v0.123.8-5fed9c591b694f314e5939548e11cc3dcb79a79c+extended windows/amd64 BuildDate=2024-03-07T13:14:42Z VendorInfo=gohugoio
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.22.0"
github.com/sass/libsass="3.6.5"
github.com/webmproject/libwebp="v1.3.2"

I tried to create a small test site based on your detailed description above:

git clone --single-branch -b hugo-forum-topic-48725 https://github.com/jmooring/hugo-testing hugo-forum-topic-48725
cd hugo-forum-topic-48725
hugo server

I cannot reproduce the problem. Tested with hugo v0.123.8-5fed9c591b.

I tried two new test sites and they all failed. Let me do further testing and see what’s wrong.

@jmooring I narrowed down the issue to the language being added to the URL (instead of /post-1-de I get /de/post-1-de. This also happened with one more test site I made. Somehow, adding url to the secondary language appends the language code to the URL.

(Also, somehow adding URL to the front matter of your example above results in it not being applied at all.).

1 Like

If I understand what you’re saying…

https://gohugo.io/content-management/urls/#url

In a monolingual site, a url value with or without a leading slash is relative to the baseURL.

In a multilingual site:

  • A url value with a leading slash is relative to the baseURL.
  • A url value without a leading slash is relative to the baseURL plus the language prefix.
Site type Front matter url Resulting URL
monolingual /about https://example.org/about/
monolingual about https://example.org/about/
multilingual /about https://example.org/about/
multilingual about https://example.org/de/about/

That leading slash was the issue. I have a site that I went with the option of not adding the language code, so I forgot that the code is added by default for secondary languages.

1 Like

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