Search code examples
hugohugo-theme

Set a localized slug also for the pages belonging to default language in Hugo


I have two languages defined on the Hugo site. By default, Hugo doesn't add a language prefix to the pages that belong to the default language.

In my case, I would also like to prefix the pages for the default language with the language prefix. And that would also require that pages of the default language to be generated into subfolder in public.

I would also like to avoid using aliases in markdown files.

Is this possible?


Solution

  • For prefix to the default language you need to add in your config.toml file one option:

    defaultContentLanguageInSubdir = true
    

    Render the default content language in subdir, e.g. content/en/. The site root / will then redirect to /en/.

    Information from here - Configuration File Documentation

    Output examples:

    • http://localhost:1313/about/ - without the option
    • http://localhost:1313/eu/about/ - with the option

    But I do not know if it will satisfied your required about "subfolder in public".