For Baidu and other search engines"WWW"Identify the domain name with a prefix:Www.abc.comAndAbc.comIt is identified as two different domain names. The consequence of doing so is to spread the attention of the website, which is not conducive to the promotion and promotion of the website.
Only throughResponse. RedirectMethod to redirect the connection. Although the connection can be redirected, the problem of scattered search engine identification cannot be solved. This problem can be solved through 301 redirection.ASP. NETYou can use the following methods to handle this problem:
1 Private Void Checktopdomainname (httpcontext context)
2 {
3 Uri url = context. Request. url;
4 String Host = URL. Host. tolower ();
5
6 Int Count = host. Split ( ' . ' ). Length;
7 Bool Doubledomainname = host. endswith ( " .Com.cn " , Stringcomparison. currentcultureignorecase) |
8 Host. endswith ( " .Net.cn " , Stringcomparison. currentcultureignorecase) |
9 Host. endswith ( " .Gov.cn " , Stringcomparison. currentcultureignorecase) |
10 Host. endswith ( " .Org.cn " , Stringcomparison. currentcultureignorecase );
11
12 If (COUNT = 2 | (COUNT = 3 & Doubledomainname ))
13 {
14 Context. response. Status = " 301 moved permanently " ;
15 // Avoid replacing the domain name in the following parameters
16 Context. response. addheader (
17 " Location " ,
18 URL. absoluteuri. Replace (
19 String . Format ( " Http: // {0} " , Host ),
20 String . Format ( " Http: // www. {0} " , Host)
21 )
22 );
23 }
24}