]> Cypherpunks repositories - gostls13.git/commitdiff
http: redirect to correct URL
authorRuss Cox <rsc@golang.org>
Tue, 24 Nov 2009 19:47:53 +0000 (11:47 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 24 Nov 2009 19:47:53 +0000 (11:47 -0800)
R=r, r1
https://golang.org/cl/157154

src/pkg/http/fs.go

index 55b6f267ed82a192d8ca9d15c22d1b8d1468dd81..507ce33a9827bc6c4df75a59a9f58789dfaf3f92 100644 (file)
@@ -75,10 +75,9 @@ func dirList(c *Conn, f *os.File) {
 func serveFileInternal(c *Conn, r *Request, name string, redirect bool) {
        const indexPage = "/index.html";
 
-       // redirect to strip off any index.html
-       n := len(name) - len(indexPage);
-       if n >= 0 && name[n:] == indexPage {
-               Redirect(c, name[0:n+1], StatusMovedPermanently);
+       // redirect .../index.html to .../
+       if strings.HasSuffix(r.URL.Path, indexPage) {
+               Redirect(c, r.URL.Path[0:len(r.URL.Path)-len(indexPage)+1], StatusMovedPermanently);
                return;
        }