From 2afe4f0205a1652ab673193e1254bd86425f7eba Mon Sep 17 00:00:00 2001 From: Sven Nebel Date: Sun, 8 Sep 2019 20:15:40 +0100 Subject: [PATCH] Redirect over routePrefix on non-matching path Signed-off-by: Sven Nebel --- main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f6ad1ee6c..efef50ac3 100644 --- a/main.go +++ b/main.go @@ -237,7 +237,7 @@ func run() int { *routePrefix = beURL.Path } - // RoutePrefix must always be at least '/'. + // routePrefix must always be at least '/'. *routePrefix = "/" + strings.Trim(*routePrefix, "/") level.Debug(logger).Log("routePrefix", *routePrefix) @@ -345,6 +345,11 @@ func run() int { w.Write(c) }) + // Redirect over routePrefix for any other path + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, *routePrefix, http.StatusFound) + }) + srv := http.Server{Addr: *listenAddress} srvc := make(chan struct{}) term := make(chan os.Signal, 1)