【问题标题】:to domains point to same host... change domain 1 requests to domain 2到域指向同一主机...将域 1 请求更改为域 2
【发布时间】:2016-07-04 16:23:22
【问题描述】:

我有两个域:www.Domain1.com 和 www.Domain2.com,它们指向同一个主机(域名服务器)。

我最终将逐步淘汰 www.domain1.com,但现在需要它。我在 www.domain2.com 上设置了 SSL。

如果用户请求http://www.domain1/About,我想将它们路由到。

换句话说,我希望对第一个域的每个请求都转到第二个域,因为稍后我将逐步淘汰 #1,并且我仅在 #2 上使用 SSL。

不知道该怎么做。

【问题讨论】:

  • 一个简单的方法是建立一个由domain1指向的小应用程序,它只是提供到新域的重定向。

标签: asp.net-mvc


【解决方案1】:

只是关于我最终如何做到这一点的更新。

1) 我用我的主机设置了一个域指针。 Domain1.com 指向 Domain2.com(都指向同一个主机位置)

2) 因为我在 Domain2.Com 上设置了 SSL,所以我在 Global.asx.cs 中设置了一个 Aplplication_BeginRequest 来调整从 Domain1.com 到 Domain2.com 的 URL。它也强制使用 SSL。这会立即路由到 Domain2.com 并使 SSL 满意。

代码见下:

        protected void Application_BeginRequest(object sender, EventArgs e)
    {
        string currentUrl = HttpContext.Current.Request.Url.ToString().ToLower();

        if (currentUrl.StartsWith("http://domain1.net"))
        {
            string newUrl = Request.Url.AbsoluteUri.Replace("http://domain1.net", "https://domain2.net");
            Response.Redirect(newUrl);
        }
        else if (currentUrl.StartsWith("https://domain1.net"))
        {
            string newUrl = Request.Url.AbsoluteUri.Replace("https://domain1.net", "https://domain2.net");
            Response.Redirect(newUrl);
        } else if (currentUrl.StartsWith("http://www.domain1.net"))
        {
            string newUrl = Request.Url.AbsoluteUri.Replace("http://www.domain1.net", "https://domain2.net");
            Response.Redirect(newUrl);
        }
        else if (currentUrl.StartsWith("https://www.domain1.net"))
        {
            string newUrl = Request.Url.AbsoluteUri.Replace("https://www.domain1.net", "https://domain2.net");
            Response.Redirect(newUrl);
        }

    }

其他对我有帮助的帖子:

How to redirect HTTP to HTTPS in MVC application (IIS7.5)

【讨论】:

    【解决方案2】:

    使用 HTTP 重定向。

    以下是 IIS 7 的说明: https://technet.microsoft.com/en-us/library/cc732969(v=ws.10).aspx

    如果您需要保留查询字符串,这有点违反直觉。不要使用相对的目的地,而是使用确切的目的地,然后添加 $V$Q。

    因此,使用您的示例,您将配置为来自 www.domain1.com 的请求提供服务的站点,将 HTTP 重定向设置到 https://www.domain2.com$V$Q 的确切目标

    以这种方式设置的示例:https://msftplayground.com/2011/01/http-redirect-with-query-string-in-iis-7/

    【讨论】:

      猜你喜欢
      • 2014-07-06
      • 2020-04-24
      • 1970-01-01
      • 2022-01-26
      • 2019-05-18
      • 2011-07-24
      • 1970-01-01
      • 2018-05-02
      • 2016-09-17
      相关资源
      最近更新 更多