开发者

Permanent Redirect in ASP.NET 4.0

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 n开发者_开发知识库o 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?


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.


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."));
    }
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜