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.
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.
Next, we write the following code in Global.asax which redirects
all traffic to the new server.
sender, EventArgs e)
string url =
string QueryParams =
if (QueryParams !=
"http://new.pageflakes.com" + url +
"http://new.pageflakes.com" + url );
So, anyone trying to go to
gets redirected to new.pageflakes.com/aboutus.html. The redirector
keeps the query string and logical path intact. So, complicated
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?