From 9aa2e5b575ba23b57130ab0a849cd1bf4dae90a3 Mon Sep 17 00:00:00 2001 From: youngsterxyf Date: Sun, 13 Mar 2016 21:39:26 +0800 Subject: [PATCH] =?UTF-8?q?fix=20issue#1787:=20The=20cause=20is=20that=20i?= =?UTF-8?q?f=20the=20url=20is=20/m=EF=BC=8Cand=20we=20set=20beego.BConfig.?= =?UTF-8?q?WebConfig.DirectoryIndex=20=3D=20true,=20then=20it=20should=20r?= =?UTF-8?q?edirect=20to=20/m/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- staticfile.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/staticfile.go b/staticfile.go index 0aad2c81..1cd75b8c 100644 --- a/staticfile.go +++ b/staticfile.go @@ -54,8 +54,13 @@ func serverStaticRouter(ctx *context.Context) { return } if fileInfo.IsDir() { - //serveFile will list dir - http.ServeFile(ctx.ResponseWriter, ctx.Request, filePath) + requestURL := ctx.Input.URL() + if requestURL[len(requestURL)-1] != '/' { + ctx.Redirect(302, requestURL+"/") + } else { + //serveFile will list dir + http.ServeFile(ctx.ResponseWriter, ctx.Request, filePath) + } return }