From 769f7c751b54615fc64de021ac0bff543d9570d2 Mon Sep 17 00:00:00 2001 From: "asta.xie" Date: Wed, 12 Mar 2014 21:06:20 +0800 Subject: [PATCH] fix static file route --- router.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/router.go b/router.go index 7d396387..62f3a1c5 100644 --- a/router.go +++ b/router.go @@ -546,6 +546,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) //static file server for prefix, staticDir := range StaticDir { + if len(prefix) == 0 { + continue + } if r.URL.Path == "/favicon.ico" { file := path.Join(staticDir, r.URL.Path) if utils.FileExists(file) { @@ -558,6 +561,10 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) if len(r.URL.Path) > len(prefix) && r.URL.Path[len(prefix)] != '/' { continue } + if r.URL.Path == prefix && prefix[len(prefix)-1] != '/' { + http.Redirect(rw, r, r.URL.Path+"/", 302) + goto Admin + } file := path.Join(staticDir, r.URL.Path[len(prefix):]) finfo, err := os.Stat(file) if err != nil {