Retain a Microsoft.NET site’s ranking with search engines with the help of 301 redirection
Web sites on the internet need to undergo technological changes or revamps. This results in the same features and functions to be available at a different URL.
If visitors to your site have bookmarked such pages of the site prior to it undergoing the revamp, their attempts to access the site after the revamp are going to result into 404 (page not found) errors.
This causes the site to be black listed / de-ranked with search engines.
Assuming that your new site is built using Microsoft .NET, this document is to illustrate an easy way in .NET to retain a site’s ranking with the help of a 301 re-direction.
What is 301 redirect?
The code 301 is interpreted as “Moved Permanantly”. 301 redirect is the most efficient and Search Engine Friendly method for webpage redirection.
How does IIS do it?
There needs to be a source page and a destination page. So when someone tries to access the source page (the URL for which is now changed) IIS transfers the visitor to the destination page.
Changes to be done in the IIS settings
Go to Start > Programs > Administrative Tools > Internet Services Manager.
Choose the instance of the server you want to forward. Choose the website to be forwarded and right click on the page that needs to redirected. From the menu choose properties to bring up the following dialog box.

Select the radio button for “A redirection to a URL”
Enter the new Redirect to URL.
For 301 redirection check against “A permanent redirection for this resource.”
This will enable 301 redirection for the page.
What if the source page does not exist?
It is possible that the source page no longer exists on the web server. This can arise if for example the earlier site was in PHP and you have migrated it to .NET. So all your pages will now be .aspx pages.
So there will be no page to right click on and bring up the properties dialog box to make the redirection settings above.
In such a case IIS needs to be tricked. Create a dummy / empty page with the name of the old file in the virtual directory of the new website. This will make that page appear in IIS. After the settings are completed, the dummy file should be deleted.
Handling query string parameters with a hashtable
The old page’s URL could be composed of query string parameters. These parameters could be different in different scenarios. Visitors to the website prior to the change in the URL would have bookmarked the URLs along with the query string parameters.
Here is a way to handle this situation and ensure that the old query string parameters are replaced with the new ones.
This can be done in C# using a hashtable.
Create a new .ASPX page and apply the 301 redirection such that all the requests to the old page are redirected to this new page.
Create a Hashtable whose key is the querystring from the old page and whose value is the querystring of the new page.
So when a request arrives at this page, the code should get the querystring parameters of the old page and hash into the hash table with it. The value stored against this URL will be the new querystring.
Append this string to the new server/ domain name and do a Response.Redirect passing the new URL to it.
The source code for the .aspx page is as follows
{codecitation class="brush:csharp"}