# HG changeset patch # User Kim Alvefur # Date 1336781828 -7200 # Node ID 550f0a5e85c5046644b61c24d40503c6aed14b33 # Parent 8974a9b7363f86163bfbc8bc24f6cecc0f26c2f9 mod_http_files: Respond with a 301 redirect for directories to append a / (fixes relative links) diff -r 8974a9b7363f -r 550f0a5e85c5 plugins/mod_http_files.lua --- a/plugins/mod_http_files.lua Sat May 12 00:33:04 2012 +0100 +++ b/plugins/mod_http_files.lua Sat May 12 02:17:08 2012 +0200 @@ -27,11 +27,18 @@ function serve_file(event, path) local response = event.response; + local orig_path = event.request.path; local full_path = http_base.."/"..path; if stat(full_path, "mode") == "directory" then - if stat(full_path.."/index.html", "mode") == "file" then - return serve_file(event, path.."/index.html"); + if full_path:sub(-1) ~= "/" then + response.headers.location = orig_path.."/"; + return 301; end + if stat(full_path.."index.html", "mode") == "file" then + return serve_file(event, path.."index.html"); + end + + -- TODO File listing return 403; end local f, err = open(full_path, "rb");