如何将* .appspot.com重定向到自定义域

如何将* .appspot.com重定向到自定义域,第1张

如何将* .appspot.com重定向到自定义域

您可以

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))


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5476499.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存