Redirect to root when DefaultContentLanguageInSubdir = false
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 9 Sep 2016 15:40:56 +0000 (17:40 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 9 Sep 2016 15:42:02 +0000 (17:42 +0200)
Fixes #2422

hugolib/hugo_sites_test.go
hugolib/site.go

index 4a60013393b31d148f83d0aea424a92bcd4895b5..bae7c1e08a713ba1ecc57aabbdb4a5573cb713c3 100644 (file)
@@ -93,6 +93,9 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) {
        if defaultInSubDir {
                // should have a redirect on top level.
                assertFileContent(t, "public/index.html", true, `<meta http-equiv="refresh" content="0; url=http://example.com/blog/fr" />`)
+       } else {
+               // should have redirect back to root
+               assertFileContent(t, "public/fr/index.html", true, `<meta http-equiv="refresh" content="0; url=http://example.com/blog" />`)
        }
        assertFileContent(t, "public/fr/index.html", defaultInSubDir, "Home", "Bonjour")
        assertFileContent(t, "public/en/index.html", defaultInSubDir, "Home", "Hello")
index 3e537c93ddbfa1dac18726ffa8bbc2b3a047b464..6bff3b038e1b144446da9f738072ef7a6dbc043e 100644 (file)
@@ -1457,12 +1457,20 @@ func (s *Site) renderAliases() error {
                }
        }
 
-       if s.owner.multilingual.enabled() && s.Info.defaultContentLanguageInSubdir {
+       if s.owner.multilingual.enabled() {
                mainLang := s.owner.multilingual.DefaultLang.Lang
-               mainLangURL := helpers.AbsURL(mainLang, false)
-               jww.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
-               if err := s.publishDestAlias(s.languageAliasTarget(), "/", mainLangURL); err != nil {
-                       return err
+               if s.Info.defaultContentLanguageInSubdir {
+                       mainLangURL := helpers.AbsURL(mainLang, false)
+                       jww.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
+                       if err := s.publishDestAlias(s.languageAliasTarget(), "/", mainLangURL); err != nil {
+                               return err
+                       }
+               } else {
+                       mainLangURL := helpers.AbsURL("", false)
+                       jww.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
+                       if err := s.publishDestAlias(s.languageAliasTarget(), mainLang, mainLangURL); err != nil {
+                               return err
+                       }
                }
        }