如何将* .appspot.com重定向到自定义域 [英] How to redirect *.appspot.com to custom domain

查看:79
本文介绍了如何将* .appspot.com重定向到自定义域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将* .appspot.com域重定向到自定义域.我想要的是像这样重定向域:

How do you redirect your *.appspot.com domain to your custom domain. What I want is redirect the domains like this:

app-id.appspot.com -> mycustomdomain.com www.mycustomdomain.com -> mycustomdomain.com

app-id.appspot.com -> mycustomdomain.com www.mycustomdomain.com -> mycustomdomain.com

注意:我正在使用go and gorilla mux.

Note: I am using go and gorilla mux.

推荐答案

您可以按照此处http.Handler组合. >重用代码.

You can do http.Handler combinatorics as described here to reuse code.

在您的情况下,组合器将如下所示(根据您的口味和要求进行调整):

In your case the combinator would look something like this (tweak it to your taste and requirements):

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)

    }
}

您可以用以下方法包装处理程序:

The you can wrap your handlers with that:

 http.Handle("/foo", NewCanonicalDomainHandler(someHandler))

这篇关于如何将* .appspot.com重定向到自定义域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆