redirect should add query params

This commit is contained in:
Maxgis 2016-07-26 19:54:10 +08:00
parent e951c555e4
commit 4b3ed53158
1 changed files with 5 additions and 1 deletions

View File

@ -57,7 +57,11 @@ func serverStaticRouter(ctx *context.Context) {
if fileInfo.IsDir() {
requestURL := ctx.Input.URL()
if requestURL[len(requestURL)-1] != '/' {
ctx.Redirect(302, requestURL+"/")
redirectURL := requestURL + "/"
if ctx.Request.URL.RawQuery != "" {
redirectURL = redirectURL + "?" + ctx.Request.URL.RawQuery
}
ctx.Redirect(302, redirectURL)
} else {
//serveFile will list dir
http.ServeFile(ctx.ResponseWriter, ctx.Request, filePath)