0

I have two domains: www.Domain1.com and www.Domain2.com that point to the same host (nameservers).

I'm ultimately going to phase out www.domain1.com, but need it to be up for now. I have SSL setup on www.domain2.com.

If the user requests http://www.domain1/About I want to route them to .

In other words I want every request to the first domain to go to the second one because I'm phasing out #1 later AND I have SSL only on #2.

Not sure how to go about this.

tereško
  • 58,060
  • 25
  • 98
  • 150
pStan
  • 1,084
  • 3
  • 14
  • 36
  • An easy way to do it would be to stand up a small application pointed at by `domain1` which simply serves a redirect to the new domain. – Rob Mar 18 '16 at 03:22

2 Answers2

1

Use HTTP redirection.

Here's the directions for IIS 7: https://technet.microsoft.com/en-us/library/cc732969(v=ws.10).aspx

If you need the querystring preserved, it's a little counter-intuitive. Rather than use a relative destination, use an exact destination, then add $V$Q.

So, using your example, you'd configure the site that's serving requests from www.domain1.com, setting HTTP redirection to an exact destination of https://www.domain2.com$V$Q

Example of setting things up this way: https://msftplayground.com/2011/01/http-redirect-with-query-string-in-iis-7/

Chris Bergin
  • 415
  • 2
  • 8
0

Just an update on how I ended up doing this.

1) I setup a domain pointer with my host. Domain1.com points to Domain2.com (Both point to same host location)

2) Since I had SSL setup on Domain2.Com, I setup an Aplplication_BeginRequest in Global.asx.cs to tweak the URL from Domain1.com to Domain2.com. It forces SSL as well. This immediately routes to Domain2.com and keeps SSL happy.

See below for the code:

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

    }

Other posts that helped me with this:

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

Community
  • 1
  • 1
pStan
  • 1,084
  • 3
  • 14
  • 36