Use HTTP header status codes in ASP. NET to implement SEO

Source: Internet
Author: User

Here we will introduce some examples of SEO using HTTP header status codes during ASP. NET development. In fact, such SEO is more for the convenience of checking the error status, to achieve a better page experience, rather than simply catering to the search engine-style SEO.

We often say "404 error". Do you know what it means?

404 is actually a "status code" contained in the Http header, indicating that the Http request failed. What other common status codes are there? What is the relationship between these status codes and SEO?

Each time when the user agent can be understood as IE or Firefox) requests a URL address from the Web site, the server will reply. The reply content includes two parts: the HTTP header and the requested content. However, we can only see the content in the browser but not the header information. Therefore, we need some browser plug-ins to observe them. Personally, I use WebDeveloper for IE and Fiddler for FireFox. If you are interested, you can download them on the Internet. Both of them are quite popular. For SEO, the status code we need to know is: Redirection: 301 and 302 are deleted: 404 server error: 500 we will explain in sequence, first 302. 302 there is a common prototype in asp.net: Response. Redirect (). Please refer to the Code:

 
 
  1. protected void Button1_Click(object sender, EventArgs e)  
  2. {  
  3.     Response.Redirect("~/target.aspx");  
  4.     //Server.Transfer("~/target.aspx");  

Source. aspx indicates a Button on the page. The code in the Click event is Response. Redirect ~ /Target. aspx), click the Button on the source. aspx page to view the status code corresponding to the page. The result is 302. For example, I am using Web Development. Why can't I go to the target page after enable log? Please give me some advice if you know the reason)

 

However, you can view the details and find the impact of 302. response indicates the url to be switched.

 

The Client/Server round-trip process is actually like this:

1. click the Button to generate a send-back request. The target page of the send-back request is still source. aspx, so the request is still sent by source. the aspx page can be processed to enter the source. the Click event of the aspx page;

2. In the Click event, Response. Redirect ~ /Target. aspx:

2.1 change the status code of the Http header in the response to 302;

2.1 indicates that the page pointed to by 302 is target. aspx;

3. browser user proxy) After receiving the response header information,

3.1 change the address in the URL address bar to target. aspx;

3.2 sending a request to target. aspx is also known as Server. Transfer () as Response. Redirect (). However, when using Server. Transfer, you will find that the status code corresponding to the page is 200, and the url in the address bar does not change, it is still source. aspx! This is because Server. Transfer is fully redirected on the Server side. Therefore, it is very popular, but I think it is not so true that Server. Transfer () should be used instead of Response. Redirect () to improve performance. Because Server. Transfer () performance is improved, you should weigh the performance improvement and the resulting cost. It is difficult to give an answer directly, which depends on the specific situation for judgment.

However, I prefer not to use Server as much as possible. transfer (), because: 1. performance is not improved much, saving in fact the round-trip of header information; 2. clear URLs play an important role in both end users and development and debugging. Well, it's easy to understand 302,301. 302 means that the redirection is temporary, while 301 means permanent redirection.

In terms of SEO, 301: 1 may be used in the following situations to extend the link value and eliminate duplicate content. domain Name replacement; 2. ing between multiple domain names, for example, www.freeflying.com and www.freeflying.cn. The two domain names actually point to the same website, which leads to a large number of duplicate content and is not conducive to the ranking of the website. 3. Clear the repeat questions on the default index page: for example, if we enter "same content for different domain names", the typical issue is that after URL rewriting, www.freeflying.com/article/321.htmland www.freeing.com/article.aspx? Id = 321 points to the same webpage content. For 404, the most intuitive understanding is that the page does not exist. This is easy to understand if the website is purely static. But when the website is made dynamic, for example, www.freeflying.com/article/321.html www.freeflying.com/article.aspx? Id = 321), although the article id = 321 has been deleted or does not exist, but article. the aspx page always exists, so the HTTP header status code is not 404, but 200, indicating that the request is successful. Assume that a website has an id = 321/342/6739 ...... But the SPIDER does not know that it will still crawl. As a result, it finds that all these different URLs correspond to the same page. It will process it as a duplicate page. 500 indicates an internal program exception, such as 3/0. The Code is as follows:

 
 
  1. protected void Button1_Click(object sender, EventArgs e)  
  2. {  
  3.     int i, j;  
  4.     i = 8;  
  5.     j = 0;  
  6.     this.Label1.Text = (i / j).ToString();  
If the search engine receives a 500 status code, it will understand that the program has only encountered a temporary error, and it will continue to capture it later to check whether the problem has been resolved, this will not cause too many problems for the website-as long as you can recover it as soon as possible. However, the custom M error web. config configuration provided by Asp.net will inadvertently "fail ". The reason is similar to that mentioned above when 404 is changed to 200. after aspx, the Spider gets a successful Link error. aspx Code 200, so the SPIDER will think the error originpage. the normal display content of aspx is error. the content of aspx. The originpage. aspx of different url parameters will be considered by the spider as different URLs, so the SPIDER will think that all these URLs are duplicated-the consequence is very serious.

Well, after realizing the seriousness of the problem, it's too easy to look at the solution.

 
 
  1. Protected void Page_Load (object sender, EventArgs e)
  2. {
  3. // If you want the search engine to know that this url will no longer be used
  4. Response. StatusCode = 404;
  5.  
  6. // If you want to tell the search engine that the url is temporarily faulty
  7. Response. StatusCode = 500;
  8.  
  9. // If You Want to redirect the page permanently
  10. Response. StatusCode = 301;
  11. Response. RedirectLocation = @ "\ website1 \ target. aspx ";
  12. }

Original article title: ASP. net seo: HTTP header status code-content redirection

Link: http://www.cnblogs.com/freeflying/archive/2010/02/24/1672308.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.