Make it always redirect to dir/ for directories otherwise it breaks HTML relatives

Signed-off-by: arzumify <jliwin98@danwin1210.de>
This commit is contained in:
Tracker-Friendly 2024-11-03 12:11:40 +00:00
parent b0fb00d7fd
commit 65de87137d
1 changed files with 5 additions and 0 deletions

View File

@ -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)