如何将* .appspot.com域重定向到自定义域。我想要的是这样重定向域:
app-id.appspot.com -> mycustomdomain.com www.mycustomdomain.com -> mycustomdomain.com
注意:我正在使用go and gorilla mux。
您可以http.Handler
按照此处所述进行组合运算以重用代码。
在您的情况下,组合器将如下所示(根据您的口味和要求进行调整):
func NewCanonicalDomainHandler(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Host != "myapp.com" {
u := *r.URL
u.Host = "myapp.com"
u.Scheme = "http"
http.Redirect(w, r, u.String(), http.StatusMovedPermanently)
return
}
next(w, r)
}
}
您可以使用以下方法包装处理程序:
http.Handle("/foo", NewCanonicalDomainHandler(someHandler))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句