Redirect to root when DefaultContentLanguageInSubdir = false

Fixes #2422
This commit is contained in:
Bjørn Erik Pedersen 2016-09-09 17:40:56 +02:00
parent 4df86a703a
commit 43bf9ed38e
2 changed files with 16 additions and 5 deletions

View file

@ -93,6 +93,9 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) {
if defaultInSubDir { if defaultInSubDir {
// should have a redirect on top level. // 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" />`) 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/fr/index.html", defaultInSubDir, "Home", "Bonjour")
assertFileContent(t, "public/en/index.html", defaultInSubDir, "Home", "Hello") assertFileContent(t, "public/en/index.html", defaultInSubDir, "Home", "Hello")

View file

@ -1457,13 +1457,21 @@ func (s *Site) renderAliases() error {
} }
} }
if s.owner.multilingual.enabled() && s.Info.defaultContentLanguageInSubdir { if s.owner.multilingual.enabled() {
mainLang := s.owner.multilingual.DefaultLang.Lang mainLang := s.owner.multilingual.DefaultLang.Lang
if s.Info.defaultContentLanguageInSubdir {
mainLangURL := helpers.AbsURL(mainLang, false) mainLangURL := helpers.AbsURL(mainLang, false)
jww.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL) jww.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
if err := s.publishDestAlias(s.languageAliasTarget(), "/", mainLangURL); err != nil { if err := s.publishDestAlias(s.languageAliasTarget(), "/", mainLangURL); err != nil {
return err 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
}
}
} }
return nil return nil