Talk about a complete guide to HTTP status codes, have you learned it?

2022.10.14

Talk about a complete guide to HTTP status codes, have you learned it?


When we enter a URL in the browser and press Enter, the browser sends an HTTP request to the site's server, the server receives and processes the request, and returns the relevant resource along with the HTTP headers.

1. Overview of HTTP Status Codes

1. Concept

When we enter a URL in the browser and press Enter, the browser sends an HTTP request to the site's server, the server receives and processes the request, and returns the relevant resource along with the HTTP headers. You can view the HTTP request status code in the browser's Network:

picture

Wikipedia's explanation of HTTP status codes:

HTTP Status Code (HTTP Status Code) is a 3-digit code used to indicate the response status of the web server Hypertext Transfer Protocol. It is defined by the RFC 2616 specification and extended by RFC 2518, RFC 2817, RFC 2295, RFC 2774, and RFC 4918. All status codes are divided into five categories, and the first digit of the status code represents one of the five statuses of the response. The message phrase shown is typical, but any readable alternative can be provided. Unless otherwise stated, status codes are part of the HTTP/1.1 standard (RFC 7231).

HTTP status codes are 3-digit codes sent from web servers (like 200 OK or 404 Not Found) to let us and search engines know if there were any errors in the request or if there was any problem with the server trying to process the request.

2. Classification

An application is usually a client making a request to a server, and the server responding. The status code is what lets us know whether the HTTP request succeeded, failed, or something else. HTTP status codes are generally divided into five categories:

category

definition

describe

1xx

Informational (informational status code)

Accepted request is being processed

2xx

Success (success status code)

The request is processed normally

3xx

Redirection (redirection status code)

Additional action is required to complete the request

4xx

Client Error (client error status code)

The server was unable to process the request

5xx

Server Error (server error status code)

Error processing request by server

3. Importance

HTTP status codes are important for diagnosing application problems, such as if a web server is not working properly and cannot serve pages, etc. Finding these issues quickly is important for developers and search engines to provide a good experience. So why are HTTP status codes and errors important for search engine optimization (SEO)?

Search engine bots see HTTP status codes when crawling websites. In some cases, these affect whether and how a page is indexed, and how search engines view a site's health.

In general, 1XX and 2XX status codes don't have much impact on SEO. Because they show that the website is up and running and enable search engine bots to continue their operations. However, they do not improve the ranking of the site. In most cases, it is the higher-level code that is important for SEO. 4XX and 5XX responses prevent bots from crawling and indexing the page. Too many errors can also indicate a low-quality site, which can lower the site's ranking.

The relationship between 3XX status codes and SEO is much more complicated. To understand their impact, you need to understand the difference between permanent redirects and temporary redirects, which will not be explained here and will be discussed in detail later. In conclusion, using permanent redirects for pages that have been migrated will have better SEO.

Status codes for 3XX, 4XX, and 5XX can be viewed in the reach report using Google Search Console:

picture

This report shows four types of pages on your site:

  • return the wrong page;
  • Pages with warnings but valid;
  • a valid page;
  • pages excluded from the index;

We can find pages with HTTP status codes of 3XX, 4XX, and 5XX in three categories other than valid pages, depending on the status code type, such as 301 redirects may appear in the last category.

picture

2. List of HTTP status codes

4XX and 5XX status codes may appear under Error.

1. 1xx Informational

The 1XX status codes were introduced in HTTP/1.1. They are informational status codes that are temporary and indicate that the request has been accepted and needs to continue processing. These status codes don't provide much useful information, and we may never see 1XX related status codes.

(1) 100 Continue

The server has received the browser's request headers and is now ready to send the request body. This makes the request process more efficient because it prevents the browser from sending the body request even if the headers have been rejected.

(2) 101 Switching Protocols

The server has accepted the client's request and will notify the client through the Upgrade header to use a different protocol to complete the request. After sending the last blank line of this response, the server will switch to the protocol defined in the Upgrade header.

(3) 102 Processing

The server has received and is processing the request and has not responded yet. This prevents the client from timing out and assuming the request is lost.

(4) 103 Early hints

Returns some response headers before the HTTP message the server responds with. This status code is used to allow user agents to preload resources while the server is ready to respond.

2. 2xx Success

2xx status codes indicate that the client's request was successfully received, understood, and accepted.

(1) 200 OK

Indicates that the request sent by the client is normally processed by the server. From an SEO standpoint, the 200 OK status code is the perfect status code for functional pages where all linked pages are working. 200 means that the search engine crawler can successfully crawl the page and put it in its search engine.

(2) 201 Created

The server fulfilled the browser's request, thus creating one or more new resources.

(3) 202 Accepted

The server has accepted the browser's request but is still processing it. The request may or may not eventually be responded to.

(4) 203 Non-authoritative Information

This status code may appear when using a proxy. This means that the proxy server received a 200 status code from the origin server, but modified the response before passing it to the browser.

(5) 204 No Content

This status code indicates that the request sent by the client has been processed normally on the server side, but there is no returned content, and the response message does not contain the main body of the entity. It is generally used when only information needs to be sent from the client to the server, and the server does not need to send content to the client.

(6) 205 Reset Content

The server successfully processed the request and returned nothing. But unlike a 204 response, a response that returns this status code requires the requester to reset the document view. This response is mainly used to reset the form immediately after accepting user input so that the user can easily start another input.

(7) 206 Partial Content

This status code indicates that the client made a range request, and the server executed this part of the GET request. The response message contains the entity content of the range specified by Content-Range.

(8) 226 IM Used

The server has successfully processed the browser's GET method to retrieve an updated version of the cached resource. Typically, a response is returned when the requested resource has one or more minor modifications.

3. 3xx Redirection

A 3XX response indicates that the browser needs to perform some special processing to properly handle the request.

(1) 300 Multiple Choices

Sometimes, the server may respond with multiple possible resources to satisfy the browser's request. The 300 status code means that the browser now needs to choose between them. This can happen when there are multiple file type extensions available.

(2) 301 Moved Permanently

Permanent redirect. A new permanent URI has been assigned to the target resource. The new URI will be specified in the Location header field in the HTTP response header. If the user has saved the original URI as a bookmark, the bookmark will be re-saved according to the new URI in Location. At the same time, the search engine also replaces the old URL with the redirected URL while crawling the new content.

(3) 302 Found

Temporary redirect. The requested resource is assigned a new URI, and it is hoped that the user (this time) can use the new URI to access the resource. Similar to the 301 Moved Permanently status code, but the resource represented by 302 is not permanently redirected, but only temporarily. That is to say, the URI corresponding to the moved resource may change in the future.

If the user saves the URI as a bookmark, the bookmark will not be updated as when the 301 status code appears, but the URI corresponding to the page that returns the 302 status code is still retained. At the same time, search engines crawl new content while keeping old URLs. Because the server returns a 302 code, the search engine considers the new URL to be temporary.

scenes to be used:

Users who are not logged in visit the User Center and are redirected to the login page.

A visit to a 404 page redirects to the homepage.

(4) 303 See Other

Since there is another URI for the resource corresponding to the request, the GET method should be used to obtain the requested resource.

The 303 status code and the 302 Found status code have similar functions, but the 303 status code clearly indicates that the client should use the GET method to obtain the resource. The 303 status code is usually used as the return result of a PUT or POST operation. It indicates that the redirect link does not point to a newly uploaded resource, but to another page, such as a message confirmation page or an upload progress page. The method of requesting a redirected page should always use GET.

Notice:

When the 301, 302, and 303 response status codes are returned, almost all browsers will change the POST to GET, and delete the body in the request message, and then the request will be automatically sent again.

The 301 and 302 standards prohibit changing the POST method into a GET method, but in practice everyone does it.

(5) 304 Not Modified

Browser cache related. This status code indicates that when the client sends a conditional request, the server allows the request to access the resource, but the condition is not met. A 304 status code is returned without any body part of the response. 304, although classified in the 3XX category, has nothing to do with redirects.

Conditional request (Http conditional request): use the Get method to request, and the request message contains any header in (if-match, if-none-match, if-modified-since, if-unmodified-since, if-range) .

Status code 304 is not an error, but tells the client that there is a cache, and the data in the cache is used directly. Only the header information is returned to the page, and there is no content part, which improves the performance of the web page to a certain extent.

(6) 305 Use Proxy

The server needs a proxy to return the requested resource. This response code is not currently used because most browsers currently do not support it due to security concerns.

(7) 307 Temporary Redirect

Temporary redirect. This status code has the same meaning as 302 Found. Although the 302 standard prohibits POST from becoming GET, it is still used in actual use. 307 will follow browser standards and will not change from POST to GET. However, different browsers still have different situations when dealing with requests. The specification requires the browser to continue POSTing to the Location's address. The specification requires the browser to continue POSTing to the Location's address.

(8) 308 Permanent Redirect

Permanent redirect, where current and future requests are redirected to a new URL.

4. 4xx Client errors

(1) 400 Bad Request

There is a syntax error in the request message. When an error occurs, you need to modify the content of the request and send the request again.

(2) 401 Unauthorized

The sent request needs to have authentication information through HTTP authentication (BASIC authentication, DIGEST authentication). If a request has been made before, it means that the user authentication failed. A response containing a 401 MUST include a WWW-Authenticate header applicable to the requested resource to challenge user information. When the browser receives a 401 response for the first time, a dialog window for authentication will pop up.

(3) 402 Payment Required

Reserved for digital payment systems. However, it is not widely used.

(4) 403 Forbidden

The client request has been denied because the client does not have permission to access the content. Unlike 401, the server knows the identity of the client, but refuses to provide a proper response because they do not have permission to view the content.

(5) 404 Not Found

The requested resource could not be found on the server, but may be available in the future. In addition, it can also be used when the server side rejects the request and does not want to give a reason.

(6) 405 Method Not Allowed

The server recognizes the HTTP request method used by the browser, but needs to use a different method to serve the required resource. Servers should always allow clients access using the GET and HEAD methods.

The client can check the access methods allowed by the server through the OPTIONS method (preflight), as follows

Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE
  • 1.

(7) 406 Not Acceptable

The server informs the client that no resource meets the criteria requested by the browser.

(8) 407 Proxy Authentication Required

The client must first authenticate with the proxy.

(9) 408 Request Timeout

This status code is generated when the server times out while waiting for a complete request from the browser. In other words, the server did not receive the full request sent by the browser. One possible cause is network congestion causing packet loss between the browser and the server.

(10) 409 Conflict

The server was unable to process the browser's request because of a conflict with the associated resource. This sometimes happens due to multiple simultaneous edits.

(11) 410 Gone

The requested resource will no longer be available in the future.

(12) 411 Length Required

The requested resource requires the client to specify a certain length, which is defined by Content-Length.

(13) 412 Precondition Failed

The server did not meet one or more of the prerequisites indicated in the request header fields.

(14) 413 Payload Too Large

The server refused to process the request because the request load was greater than the server could or was willing to handle. While the server may close the connection to prevent the client from continuing the request, it SHOULD generate a Retry-After header field and how long after the client can retry.

(15) 414 Request-URI Too Long

The request from the browser cannot be processed by the server because the client encodes too much data into a query string and sends it as a GET method.

(16) 415 Unsupported Media Type

The request has been rejected by the server because it does not support the media format of the requested data.

(17) 416 Requested Range Not Satisfiable

The range specified in the request's Range header could not be satisfied. The reason may be that the given range exceeds the size of the target URI data.

(18) 417 Expectation Failed

The server was unable to meet the requirements specified in the Expect field of the request's request header.

(19) 421 Misdirected Request

The browser's request has been redirected to another server, which cannot produce a response.

(20) 422 Unprocessable Entity

There is a semantic error in the request made by the browser and the server cannot handle it.

(21) 423 Locked

Access to the required resource is denied because it is locked.

(22) 424 Failed Dependency

The request made by the browser failed because it depended on another request, which failed.

(23) 426 Upgrade Required

When the server refuses to perform a given request using the current protocol, it may be willing to perform the request after the client has upgraded to a different protocol.

(24) 428 Precondition Required

The server requires that conditions be specified before processing the request.

(25) 429 Too Many Requests

This is generated by the server when a user sends too many requests in a given amount of time (rate limiting). This can sometimes be caused by bots or scripts trying to access the site.

(26) 431 Request Header Fields Too Large

The server cannot process the request because the header field is too large. This could be a problem with a single header field or all header fields.

(27) 451 Unavailable For Legal Reasons

The operator of the server received a request to prohibit access to the requested resource.

(28) 499 Client closed request

This status code is returned by nginx when the client closes the connection while nginx is processing a request.

5. 5xx Server Error

A 5XX response indicates an error on the server itself.

(1) 500 Internal Server Error

An error occurred on the server side while executing the request. It is also possible that the application has a bug or some temporary glitch.

(2) 501 Not Implemented

The request could not be processed because the server does not support it.

(3) 502 Bad Gateway

The server acting as a gateway or proxy received an invalid response from an upstream server. Note that 502 errors are usually not fixable by the client, but need to be fixed by the passing server or proxy server

(4) 503 Service Unavailable

The server is temporarily overloaded or is undergoing maintenance downtime and cannot process requests now.

scenes to be used:

When the server is down for maintenance, it will actively respond to the request with 503;

nginx sets a speed limit, if the speed limit is exceeded, 503 will be returned.

(5) 504 Gateway Timeout

The server of the gateway or proxy cannot get the desired response within the specified time. It is new in HTTP 1.1.

scenes to be used:

Code execution time out;

The code has an infinite loop.

(6) 505 HTTP Version Not Supported

The HTTP version used in the request is not supported by the server.

(7) 506 Variant Also Negotiates

Server internal configuration error.

(8) 507 Insufficient Storage

The server cannot store what is necessary to complete the request.

(9) 508 Loop Detected

The server detected an infinite loop while processing the request.

(10) 510 Not Extended

The server needs to be scaled further to serve the request.

(11) 511 Network Authentication Required