diff --git a/httphandlers.go b/httphandlers.go index 45ee5fa..077962c 100644 --- a/httphandlers.go +++ b/httphandlers.go @@ -57,8 +57,15 @@ func GetHandler(config Config) http.HandlerFunc { http.Error(w, "Permission denied.", http.StatusForbidden) return } - // Add index.html to directory paths, if it exists + // Handle URLS which map to a directory if info.IsDir() { + // Redirect to add trailing slash if missing + // (otherwise relative links don't work properly) + if !strings.HasSuffix(r.URL.Path, "/") { + http.Redirect(w, r, r.URL.String()+"/", http.StatusMovedPermanently) + return + } + // Add index.html to directory paths, if it exists index_path := filepath.Join(path, "index.html") index_info, err := os.Stat(index_path) if !os.IsNotExist(err) {