mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
Redirect to root when DefaultContentLanguageInSubdir = false
Fixes #2422
This commit is contained in:
@@ -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")
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user