Repository: gohugoio/hugo (language: go)

Issue:
Hugo should have some way to disable root index.html generation if it is available in static folder
I lookup the web and ask AI engines without result.
I am using "DefaultContentLanguageInSubdir = true" for multiple language site. I have my own logic/algorithm for index.html in the output root.

I have no way to disable the generation of index.html that will redirect to one of the languages.
None of the solutions on the web works.


Discussion / hints:

Fix patch:
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go
index b158d8a90bd..be4480f45d2 100644
--- a/config/allconfig/allconfig.go
+++ b/config/allconfig/allconfig.go
@@ -505,6 +505,9 @@ type RootConfig struct {
 	// Set this to true to put all languages below their language ID.
 	DefaultContentLanguageInSubdir bool
 
+	// Disable generation of redirect to the default language when DefaultContentLanguageInSubdir is enabled.
+	DisableDefaultLanguageRedirect bool
+
 	// Disable creation of alias redirect pages.
 	DisableAliases bool
 
diff --git a/hugolib/site_render.go b/hugolib/site_render.go
index 83f2fce8971..e5b2b62ab71 100644
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -334,6 +334,9 @@ func (s *Site) renderAliases() error {
 // renderMainLanguageRedirect creates a redirect to the main language home,
 // depending on if it lives in sub folder (e.g. /en) or not.
 func (s *Site) renderMainLanguageRedirect() error {
+	if s.conf.DisableDefaultLanguageRedirect {
+		return nil
+	}
 	if s.h.Conf.IsMultihost() || !(s.h.Conf.DefaultContentLanguageInSubdir() || s.h.Conf.IsMultilingual()) {
 		// No need for a redirect
 		return nil


Test patch:
diff --git a/hugolib/config_test.go b/hugolib/config_test.go
index c9db0d2f008..c0bfde37da4 100644
--- a/hugolib/config_test.go
+++ b/hugolib/config_test.go
@@ -1339,6 +1339,29 @@ Home.
 	b.Assert(len(b.H.Sites), qt.Equals, 1)
 }
 
+func TestDisableDefaultLanguageRedirect(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+defaultContentLanguageInSubdir = true
+disableDefaultLanguageRedirect = true
+[languages]
+[languages.en]
+title = "English Title"
+[languages.sv]
+title = "Swedish Title"
+-- layouts/index.html --
+Home.
+
+
+`
+	b := Test(t, files)
+
+	b.Assert(len(b.H.Sites), qt.Equals, 2)
+	b.AssertFileExists("public/index.html", false)
+}
+
 func TestLoadConfigYamlEnvVar(t *testing.T) {
 	defaultEnv := []string{`HUGO_OUTPUTS=home: ['json']`}