What is an HTTP response code?
An HTTP code is a standard numeric response from a web server to a request sent by a browser. This code indicates the result of that request, whether it is a success, an error, a redirect, or other types of responses. When you enter a URL into your web browser, such as Chrome or Mozilla, a request is sent to the web server hosting that URL. The server responds with an HTTP code that informs your browser how the request was handled.
Roles and importance of HTTP code
Diagnosis and Troubleshooting: HTTP codes play a crucial role for webmasters and site administrators. An HTTP error code like “404 Not Found” indicates that a web page cannot be found on the server. Such an error message can be caused by a broken link, a manually moved or deleted file, or an error in the server configuration file, such as .htaccess
for Apache or nginx.conf
Nginx.
Search Engine Optimization (SEO) : Search engines, such as Google, look at HTTP codes to index and rank websites. A site that consistently returns errors such as “500 Internal Server Error” can be penalized in search rankings. Proper use of redirects, such as the “301 Moved Permanently” code, signals to search engines that the content has moved to a new address.
Improved user experience: Proper use of HTTP codes ensures that users are correctly redirected to active pages, receive relevant error messages if they request an unavailable resource, and can successfully log in or authenticate.
Classification of HTTP codes
- 1xx (Informational Responses): The request has been received and is being processed. For example, “100 Continue” indicates that everything is fine and the client can continue sending its request.
- 2xx (Success Responses): The request was received, understood, and accepted. The most common code is “200 OK” and indicates that the request was successful.
- 3xx (Redirect Responses): These codes indicate that the client must take additional action to complete the request. For example, “303 See Other” redirects the browser to another URL.
- 4xx (Client-side errors): These indicate that the request seems to be incorrect. The “404 Not Found” code is one of the most recognized, meaning that the requested page cannot be found.
- 5xx (Server-Side Errors): These codes indicate that the server failed to execute a valid request. “500 Internal Server Error” is a common example.
HTTP codes can be configured and customized to each site's specific needs. Some popular CMSs, such as WordPress, offer plugins and extensions to help manage these codes. Web servers, such as Apache (often referred to as “apache2” in environments like UNIX) or Nginx, allow detailed configuration of HTTP codes via specific configuration files.
It should also be noted that additional services and protocols, such as FTP for file transfer, SSL for security, or SMTP for email, may also interact with or influence how HTTP codes are generated and processed.
What are the most common HTTP response codes?
HTTP response codes are standardized indicators that indicate the result of a request made to a web server. Here are the most common HTTP response codes, categorized by category:
1xx – Informational Responses: These codes indicate that the request has been received and the process is in progress.
- 100 Continue: The client's initial request has been received and the client should continue sending the remainder of the request.
- 101 Switching Protocols: The server understands and is ready to respond to the client's request to use another protocol.
2xx – Success Responses: The request was processed successfully.
- 200 OK: The request was successful. This is the standard response for successful requests.
- 201 Created: The request was processed and resulted in the creation of a resource.
- 204 No Content: The request was processed successfully, but there is no content to return.
3xx – Redirect Responses: The request requires additional actions to complete.
- 301 Moved Permanently: The requested resource has been permanently moved to a new URL.
- 302 Found (or Moved Temporarily): The requested resource has been temporarily moved, but will likely return to its original location in the future.
- 304 Not Modified: The resource has not been modified since the last request.
4xx – Client-side errors: There was a problem with the request.
- 400 Bad Request: The request cannot be processed due to bad syntax.
- 401 Unauthorized : The request requires user authentication.
- 403 Forbidden: The server understood the request, but refuses to process it. Unlike 401, authentication will make no difference.
- 404 Not Found: The requested resource is not available.
- 429 Too Many Requests: The client sent too many requests in a given time frame.
5xx – Server-side errors: The server failed to process a valid request.
These codes allow developers and website administrators to quickly understand the status of requests and act accordingly.