From 428190254510d3bc6eabf290fb138980784c38bb Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 22 Dec 2006 19:06:16 +0000 Subject: [PATCH] [Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work. --- Lib/SimpleHTTPServer.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/SimpleHTTPServer.py b/Lib/SimpleHTTPServer.py index fae551a565..86c669ea40 100644 --- a/Lib/SimpleHTTPServer.py +++ b/Lib/SimpleHTTPServer.py @@ -66,6 +66,12 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): path = self.translate_path(self.path) f = None if os.path.isdir(path): + if not self.path.endswith('/'): + # redirect browser - doing basically what apache does + self.send_response(301) + self.send_header("Location", self.path + "/") + self.end_headers() + return None for index in "index.html", "index.htm": index = os.path.join(path, index) if os.path.exists(index): -- 2.50.1