From 65de87137d646a8ee685d3653dc6d880a61fc0b0 Mon Sep 17 00:00:00 2001 From: arzumify Date: Sun, 3 Nov 2024 12:11:40 +0000 Subject: [PATCH] Make it always redirect to dir/ for directories otherwise it breaks HTML relatives Signed-off-by: arzumify --- main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.go b/main.go index aebb7b6..6c17475 100644 --- a/main.go +++ b/main.go @@ -385,6 +385,11 @@ func newFileServer(root string, directoryListing bool) http.Handler { _, err := os.Stat(filepath.Join(root, filepath.FromSlash(r.URL.Path), "index.html")) if err != nil { if directoryListing { + // Check if the path ends with a slash + if !strings.HasSuffix(r.URL.Path, "/") { + http.Redirect(w, r, r.URL.Path+"/", 301) + return + } listDirectory(w, r, root) } else { serverError(w, 403)