diff --git a/assets/templates/404.gohtml b/assets/templates/404.gohtml index d411f1c72..dca4dd96e 100644 --- a/assets/templates/404.gohtml +++ b/assets/templates/404.gohtml @@ -2,7 +2,7 @@ - + {{if .redirect }}{{end}} diff --git a/internal/api/abort.go b/internal/api/abort.go index 76e4d2b5b..f2c3194ef 100644 --- a/internal/api/abort.go +++ b/internal/api/abort.go @@ -39,12 +39,21 @@ var AbortNotFound = func(c *gin.Context) { case gin.MIMEJSON: c.JSON(http.StatusNotFound, gin.H{"error": i18n.Msg(i18n.ErrNotFound)}) default: - values := gin.H{ - "signUp": gin.H{"message": config.MsgSponsor, "url": config.SignUpURL}, - "config": conf.ClientPublic(), - "error": i18n.Msg(i18n.ErrNotFound), - "code": http.StatusNotFound, + var redirect string + + // Redirect to site root if current path is different. + if root, path := conf.BaseUri("/"), c.Request.URL.Path; path != "" && path != root { + redirect = root } + + values := gin.H{ + "signUp": gin.H{"message": config.MsgSponsor, "url": config.SignUpURL}, + "config": conf.ClientPublic(), + "error": i18n.Msg(i18n.ErrNotFound), + "code": http.StatusNotFound, + "redirect": redirect, + } + c.HTML(http.StatusNotFound, "404.gohtml", values) }