tags:

views:

21

answers:

2

I have heard that if you have two URL's for your site i.e. http://yoursite.com and http://www.yoursite.com, it affects your SEO and page rank. Instead, one should do a permanent redirect from http:// to http://www. Is this correct?

Now I have seen all articles showing how to do it in IIS. However I have no access to IIS.

Can anyone tell me how it is done in code behind or any other method and what's the right way to do it?

A: 

inside your global.asax you can use something similar to:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (!(Request.Url.AbsoluteUri.ToLower().Contains("www")))
    {
      Response.RedirectPermanent(Request.Url.AbsoluteUri.Replace("http://", "http://www."));
    }
} 
John Boker
Response.Redirect will use a 302 status code, whereas if you did basically this but with a Response.RedirectPermanent (see my answer) it will redirect correctly with a 301.
nizmow
@nizmow edited to use RedirectPermanent
John Boker
Thanks. So there is no penalty from Search Engines if I do this now. My site is up from the past 2 years.
Goliath
There shouldn't be. You might also check out Google's Webmaster Tools, as they will give you loads of information about how Google sees your site and reveal potential issues such as this one. Check out www.google.com/webmasters/.
nizmow
Ok one last question. Is there any additional advantage if I somehow convince my host do it through IIS and not code?
Goliath
+1  A: 

Full domain redirects like the one you mention are best done at the IIS level, but if you aren't able to configure IIS you could use Response.RedirectPermanent, which is new in ASP.NET 4.0. This will redirect with a 301 (permanent) status code instead of the 302 (object moved) status code used by a standard Response.Redirect.

What you COULD do is put something in your Global.asax "Application_BeginRequest" which checks what URL is being used and potentially uses Response.RedirectPermanent to redirect to your desired URL. This is a bit of a hack, but I suppose it would work in a pinch.

nizmow