From 49db093a5129e5d086dda3f468575ca130b9fe9d Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 27 Oct 2024 21:01:44 +0200 Subject: [PATCH] fixed auto www redirect due to missing schema --- apis/middlewares.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apis/middlewares.go b/apis/middlewares.go index c5959125..ca18902a 100644 --- a/apis/middlewares.go +++ b/apis/middlewares.go @@ -246,9 +246,15 @@ func wwwRedirect(redirectHosts []string) *hook.Handler[*core.RequestEvent] { host := e.Request.Host 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( http.StatusTemporaryRedirect, - (e.Request.URL.Scheme + "://" + host[4:] + e.Request.RequestURI), + (schema + host[4:] + e.Request.RequestURI), ) }