fix issue#1787: The cause is that if the url is /m,and we set beego.BConfig.WebConfig.DirectoryIndex = true, then it should redirect to /m/

This commit is contained in:
youngsterxyf 2016-03-13 21:39:26 +08:00
parent d90195061f
commit 9aa2e5b575
1 changed files with 7 additions and 2 deletions

View File

@ -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
}