1. ./index.html
会被自动重定向到 ./
例:
原始 | 重定向后 |
---|---|
static/index.html | static/ |
/index.html | / |
而标准库则会把 ./
当作 ./index.html
处理
2. url 与 dir 的对应关系
http.Handle("/f/", http.FileServer(http.Dir("./static")))
当 req_url = "/f/f1"
时,
用过其他web框架的
大都会以为是请求文件 ./static/f1
,
而实际上则是请求文件 ./static/f/f1
要达到想要的效果则要使用 http.StripPrefix
,去掉 /f/
前缀
http.Handle("/f/", http.StripPrefix("/f/", http.FileServer(http.Dir("./static"))))
另外注意是 /f/
,而不是 /f
//不会是你想要的效果
http.Handle("/f", http.StripPrefix("/f/", http.FileServer(http.Dir("./static"))))
网友评论