It is common that when you have moved your site from one host to another and you want to redirect all the traffic going to old host to be redirect to the new host before the old host is completely unavailable.
This can be easily done with any major web server. For IIS, Microsoft has a page about this and all you need to do is follow the instruction in the section of “to redirect requests to another Web site or directory”.
Redirect requests to another Web site or directory
Sweet, now you type in a URL going to your old site and you automatically landed to the correct page on your new site. But wait, what’s going to happen if one day you have to shutdown the old site completely. Your user’s bookmark and external link from other site will still be pointing to your old site because the redirect was so transparent that they would have never notice the need to correct their bookmark. When the day comes, they’ll suddenly end up with a broken error page.
Redirect all requests to a single file
Yes, we want to put up a page to let our user know about it so they can update their bookmark during the transition period when both old and new site are up and running. Fine, let’s use the method mentioned in the section “to redirect all requests to a single file”. Now our user can see the nicely written notice that the site was moved to a new home. But wait again, what should use do next after reading our notice, they want to go to that particular page on your site! Where should they click?
Redirect requests to a program
Well, according to Microsoft, we still have last option. That is redirecting to a program that is smart enough to tell user about the move and then send the user to the right page!? This sounds like what we wanted but does it really justify to write a binary executable for such a simple task? No, there got to be a simpler and better way!
Redirect to a smart HTML page
First, configure you old site’s properties to redirect the site to exactly “http://server/move.html?$P&URI=” without quotes. Make sure none of the checkbox options in the redirect to is checked. See the screenshot below:
Then create the move.html page with below content:
var hu = window.location.search;
var position = hu.lastIndexOf('&URI=');
var query = hu.substring(0, position);
var path = hu.substring(position+5);
if (query == '?') query = '';
var url = 'http://thenewcoolsite' + path + query;
linkstring = '<a href="' + url + '">' + url + '</a>';
<title>The Cool Site Moved</title>
<h1>The Cool Site Moved</h1>
Please always use the <a href="http://thenewcoolsite/">http://thenewcoolsite/</a>
to access the the cool site.
You just landed on the old host of the cool site. This host will be taken offline
soon and you will get an error instead of this page when it happens. Please take
one of the actions below:
If you access from your web browswer's bookmark or faviorate, please update it
now with the new link below.
If you clicked on a link from an email, please notify the sender to correct the link.
If you are brought to this page by an application or another web site, please notiffy
the owner of the application ASAP.
The new link to your request is in below. Please click on the link, it will take you
to the page that you are looking for.
Now if user access http://oldcoolsite/somedeeplylinked/pagewithparameter.aspx?p1=abc&p2=789, you should get the page below with messages that you want to give to user, as well as a link to the new site that that the user attempted to access.
Limitations and Enhancements