当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net - Redirect from www to non-www with using subdomain

问题描述:

I need to redirect a URL from www to non-www when user enters URL with subdomain.

Example:

www.abc.xyz.com to abc.xyz.com

网友答案:
string url = Request["HTTP_REQUEST_URL"];  // not sure the exact Constant name of the header
Uri uri = new Uri(url);
if(uri.Host.StartsWith("www.") && uri.Host.Count(c => (c == '.'))>2)
{
    Response.Redirect(url.Replace("www.", ""));
}

thought as was said before, i think it is redundant because browsers do this checks for you...
and you really should avoid being "too smart for your own good".

分享给朋友:
您可能感兴趣的文章:
随机阅读: