Redirect any pages in a old site to corresponding pages in new site

This mostly involves moving a site to another hosting company, since we can’t simply change the IP address of the new server to be the DNS-registered IP. DNS will be changed to the new IP but it takes hours for it to populate to all ISPs. We can blindly redirect all request to the home page of the new server, but that means no matter what page/querystring user requests, he/she will see the home page. Not very user friendly.

Step 1: register a new sub domain (e.g. new.myblog.com), so that user’s ISP will get the brand new IP address.

Step 2: in old server, add a Wildcard application maps to have ASP.NET engine handle all requests (html, gif etc)

Step 3: in global.asax, redirect user in Application_BegineRequest:

string url = HttpContext.Current.Request.Url.AbsolutePath;
string QueryParams = HttpContext.Current.Request.QueryString.ToString();
if ( QueryParams != “”)
{ Response.Redirect(“http://new.myblog.com” + url + “?”+ QueryParams); }
else
{ Response.Redirect(“http://new.myblog.com” + url ); }

Advertisements
This entry was posted in ASP.NET. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s