muxMaps := http.NewServeMux()
muxMaps.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {w.Write([]byte("maps page"))})
mux := http.NewServeMux()
mux.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {w.Write([]byte("main page"))})
mux.Handle("/maps/", http.StripPrefix("/maps", muxMaps))
mux.Handle("/maps1/", http.StripPrefix("/maps1", muxMaps))
http.ListenAndServe(":8000", mux)
请求“http://localhost:8000/”返回“主页”
请求“http://localhost:8000/maps 1/”返回“Map页面”
但是请求“http://localhost:8000/maps/”重定向到“http://localhost:8000/”并返回“main page”
好吧,也许顺序很重要。我试着这样做:
mux.Handle("/maps1/", http.StripPrefix("/maps1", muxMaps))
mux.Handle("/maps/", http.StripPrefix("/maps", muxMaps))
结果是不变的。
为什么?“Map”这个词有什么魔力?
1条答案
按热度按时间50pmv0ei1#
问题确实出在浏览器缓存中。