Monday, 26 April 2010
We recently migrated a clients domain from domainA.com to domainB.com.
If you are familiar with search engines and indexing, migrated domains that do not have proper 301 redirects pointing from the old domain to the new will cause the new domain to miss a lot of search engine traffic. The new domain will in fact have to start all over again and get re-indexed by search engines which can take months.

How do you prevent this?
Simple, setup a global HTTP 301 url redirect on your old domain.
Any requests to the old domain will be redirected permanently to the new domain, including the path and query so that your new domain gets all the traffic the new domain would.

Why use a HTTP 301 redirect?
Well, by doing a 301 redirect, any search engines following the redirect would remember that you want to permanently update your link. This way the SE will update its records and by doing this your domain's current rankings will be better maintained.

How do you implement a global HTTP 301 redirect?
In ASP.NET, it requires editing the global.asax's application_beginrequest event.
See the code sample below:


    protected void Application_BeginRequest(Object sender, EventArgs e)

    {

        // url exists?

        if (Request.Url != null)

        {

            // 301-redirect for domainA.com to DomainB.com

            string key = "domainA.com";

            if (Request.Url.Host.ToLower().Contains(key) == true)

            {

                Response.ClearHeaders();

                Response.Status = "301 Moved Permanently";

                Response.AddHeader("Location", "http://www.domainB.com" + Request.Url.PathAndQuery);

                return;

            }

        }

    }


So for example if we receive an incoming url on http://domainA.com/product.aspx?id=5 , this will redirected to
http://domainB.com/product.aspx?id=5.
Search engine's will update their links and your site will benefit from a good amount of traffic from your old domain.

Hope this helps you!