How to overwrite the root index.html when defaultContentLanguageInSubdir is true

Hello.

I am developing a multilanguage site with Hugo.

In my config.toml I have set defaultContentLanguageInSubdir = true that, as the documentation indicates, render the default content language in a subdir, e.g. content/en/ and the site root / will then redirect to /en/.

This redirection is created by Hugo by adding the following index.html file in the root of the site:

<!DOCTYPE html><html><head><title>http://localhost:1313/en</title><link rel="canonical" href="http://localhost:1313/en"/><meta name="robots" content="noindex"><meta charset="ut f-8" /><meta http-equiv="refresh" content="0; url=http://localhost:1313/en" /></head></h tml>

This behavior is correct. But I believed that I could create my custom index.html that I would save in the /static/ or /themes/mytheme/static/ directories and this does not work.

If I create a custom file /static/index.html or /themes/mytheme/static/index.html with, for example, a map that allows visitors to choose their preferred language other than the default one, it will work only temporarily while ‘hugo server’ is running, if I restart the server or build the site, hugo will replace my custom index.html with the redirection to the default language.

Isn’t it possible to prevent hugo from creating its own /index.html if it find a /static/index.html or /themes/mytheme/static/index.html?

The included web server is for development. If the static output of the site copies over your index.html, there’s no issue, correct? As in, run hugo sans server.

No @maiki, maybe I explained it wrong. When I said «if I restart the server or build the site» I could say «if I stop and start hugo server to restart the server or run hugo to build the site».

In addition to ~$ hugo server and ~$ hugo, I have also deployed my site on GitHub, GitLab and Netlify.

The output is always the Hugo’s predefined index.html, never the custom index.html from /static/ or /themes/theme/static/.

1 Like

@miguel did you find a solution for this?

I also want to change the generated template:

<!DOCTYPE html>
<html>
   <head>
      <title>en</title>
      <link rel="canonical" href="en"/>
      <meta name="robots" content="noindex">
      <meta charset="utf-8" />
      <meta http-equiv="refresh" content="0; url=en" />
   </head>
</html>

For one there should be a / after the url and the title should also be different.

response is here: https://gohugo.io/content-management/urls/#customize