Redirect Traffic from old to new server when you change hosting service

How do you redirect your users when you change hosting service? Currently your domain maps to the IP which is with the current hosting provider. When you change to a new hosting provider, you get a new IP range for your new servers. So, even if you change the DNS mapping, it will take at least 4 days to get refreshed all over the world. So, during these 4 days, some user will go to new IP and some will go to old IP.

The problem here is redirecting all users to the new IP without letting themknow anything.

At Pageflakes, We have done this many times. We had all sorts of problem with our hosting providers and have changed servers almost once every month. So, we had to come up with a solution which works transparently and without any downtime.

Here’s what we do. First we map a new subdomain like new.pageflakes.com to the new server IP. Then we create a new web site (not virtual directory) on old web server called “Redirectors”. It maps to a folder which has nothing but a global.asax and web.config. Then we go to Web site Properties -> Home Directory -> Configuration and map ASP.net to receive all web requests. This includes all URLs including .html, .gif, .css. Js etc.

Next, we write the following code in Global.asax which redirects all traffic to the new server.


protected
void Application_BeginRequest(Object
sender, EventArgs e)
    {


string url =
HttpContext.Current.Request.Url.AbsolutePath;

string QueryParams =
HttpContext.Current.Request.QueryString.ToString();

if (QueryParams !=
"") {
          Response.Redirect(
"http://new.pageflakes.com" + url +
"?"+ QueryParams);
   }
else {
          Response.Redirect(
"http://new.pageflakes.com" + url );
   }
    }

So, anyone trying to go to www.pageflakes.com/aboutus.html gets redirected to new.pageflakes.com/aboutus.html. The redirector keeps the query string and logical path intact. So, complicated URLs like www.pageflakes.com/flakes/amit/notepad/notepad.html?haha=huhu&hehe=hoho gets converted nicely.

After doing this, we stop the default web site which is listening to port 80 and turn on the redirector. By this time, new server is already up and running on the new subdomain.

Now we do the DNS change and map the new server’s IP to www.

So, those users who still have the old IP in their DNS cache goes to the old server and then gets redirected to the new server. But after a while when their DNS cache gets refreshed and they get the new IP, all their requests go to the new server, so we have nothing to do here. After 4 or 5 days, we can safely wipe out the old server and start kicking old hosting providers backend.

Anyone has a better idea?

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Related posts:

  1. Cost effective, failsafe, 2 server load balanced web & DB servers
  2. Simulate Windows Service using ASP.NET
  3. Redirecting traffic from http to https with zero coding in IIS
  4. 99.99% available ASP.NET and SQL Server SaaS Production Architecture
  5. How to change user name in ASP.NET 2.0 Membership Provider

No son did The God beget, Nor is there any god along with Him: (if there were Many gods), behold, each god would have taken away what he had created, and some would have lorded it over others! Glory to The God! (He is free) from the (sort of) things they attribute to Him! (Quran 23:91)

8 Comments

Leave a Reply

 

Get Adobe Flash playerPlugin by wpburn.com wordpress themes