HUGO

No language code in posts permalink in multilingual site

I have a multilingual site, nl and en. The nl-blog archive is in /blog, the en-blog archive is in /en/blog. Like it should.

My permalinks for nl are like: /2021/10/08/nederlands-bericht/ and for English: /en/2021/10/08/english-post/.

However… I want the permalinks to posts NOT have the language code prefix. So the posts should have:

/2021/10/08/nederlands-bericht/
/2021/10/08/english-post/

In a nutshell: I’d like to get rid of the language prefix in my post permalinks.

How can I achieve this?

Relevant config.toml:

[permalinks]
  blog = "/:year/:month/:day/:slug/"
[languages.en.permalinks]
  blog = "/:year/:month/:day/:slug/"

Multilingual mode is global. If your request was possible Hugo would not know which one would be the corresponding translation of a given content file.

As far as I know you can achieve what you want without using multilingual mode.

You could use two different Sections:
/blog and /en

And then configure the permalinks like so:

[permalinks]
    blog = "/:year/:month/:day/:slug/"
    en = "/:year/:month/:day/:slug/"

Thanks. That workaround would do the job, but I prefer to keep my posts in one place/folder.

Thing is, I blog mostly in my primary language, but sometimes in English. So, the posts never are translations of eachother. (And if they are, their title and slug will be different, so it shouldn’t be an issue.)

So my requirements are:

  • All posts in one section “posts
  • All posts are in a bundle
  • Dutch posts are in index.md and English posts are in index.en.md
  • List pages (homepage, section page, taxonomies etc.) permalinks are in their language folder (e.g. /tags for Dutch and /en/tags for English
  • static pages (about etc.) permalinks are in their language folder (e.g. /over for Dutch and /en/about for English
  • Permalinks for Dutch posts (in “posts” section) are in the site root ("/:year/:month/:day/:slug/")
  • Permalinks for English posts (in “posts” section) are in the site root ("/:year/:month/:day/:slug/")

Files in content folder:

about.md
about.en.md
posts
+-- 2021
    +-- 10
        +-- nederlands-bericht
            +-- index.md
        +-- english-post
            +-- index.en.md
        +-- etc.

URLs / permalinks

https://example.org/      <== root
https://example.org/over  <== static page
https://example.org/blog  <== list page
https://example.org/2021/10/08/nederlands-bericht  <== blog post

https://example.org/en
https://example.org/en/about
https://example.org/en/blog
https://example.org/2021/10/09/english-post

You will still need to remove the multilingual mode. Since you are posting different content per language you do not really need it and you cannot remove the lang code from the second language as noted above.

So with the setup you described just try:

[permalinks]
    posts = "/:year/:month/:day/:slug/"

So that /posts/ is not included in the permalink.

And also make sure to use index.md for your english language blog posts (and not index.en.md).

The bundle directory of an english language post should have an english language name and that should be enough to differentiate it from the dutch ones.

Thanks for your contribution. I’ll give this some thought.