fixed auto www redirect due to missing schema

This commit is contained in:
Gani Georgiev 2024-10-27 21:01:44 +02:00
parent 8646960abc
commit 49db093a51
1 changed files with 7 additions and 1 deletions

View File

@ -246,9 +246,15 @@ func wwwRedirect(redirectHosts []string) *hook.Handler[*core.RequestEvent] {
host := e.Request.Host host := e.Request.Host
if strings.HasPrefix(host, "www.") && list.ExistInSlice(host, redirectHosts) { if strings.HasPrefix(host, "www.") && list.ExistInSlice(host, redirectHosts) {
// note: e.Request.URL.Scheme would be empty
schema := "http://"
if e.IsTLS() {
schema = "https://"
}
return e.Redirect( return e.Redirect(
http.StatusTemporaryRedirect, http.StatusTemporaryRedirect,
(e.Request.URL.Scheme + "://" + host[4:] + e.Request.RequestURI), (schema + host[4:] + e.Request.RequestURI),
) )
} }