mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Redirect to root when DefaultContentLanguageInSubdir = false
Fixes #2422
This commit is contained in:
parent
4df86a703a
commit
43bf9ed38e
2 changed files with 16 additions and 5 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue