Server response 404 Not Found
Understanding HTTP Status Code 404 (Not Found)
The HTTP status code 404, commonly known as "Not Found," is one of the most recognized error codes in web development. It signifies that the server could not find the requested resource. This error can arise for various reasons, such as a typo in the URL, the resource being moved or deleted, or incorrect links on a webpage. In this article, we will delve into the causes of this error, practical examples of its occurrence, and solutions for handling the error across different programming languages.
Causes of the 404 Status Code
- Incorrect URL: A simple typo or misconfiguration can lead to this error.
- Resource Deletion or Movement: If a page has been removed or relocated without proper redirection, it results in a 404 error.
- Link Errors: Broken links within a site can lead users to non-existent pages.
- Server Configuration Issues: Inadequate server settings may cause the server to be unable to locate the requested resource.
Practical Examples of 404 Status Code Usage
- User Experience: The occurrence of a 404 error can significantly affect how users perceive a website. A poorly handled 404 can lead to frustration and a negative experience.
- Examples from Popular Websites: Many well-known websites, such as Google and Wikipedia, have custom-designed 404 pages that provide users with options to navigate back to functional parts of the site.
- Custom 404 Pages: Creating a personalized 404 page can enhance user interaction by offering links to relevant content or a search bar.
Handling 404 Errors in Different Programming Languages
Below are examples of how to manage 404 errors in various programming environments:
Programming Language | Example Code |
---|---|
JavaScript (Node.js) |
app.use((req, res, next) => {
|
Python (Flask) |
@app.errorhandler(404)
|
PHP |
http_response_code(404);
|
Recommendations for Improving 404 Error Handling
- Custom 404 Pages: Design user-friendly 404 pages that guide users back to the main content of the site.
- Analytics: Utilize analytics tools to monitor the frequency of 404 errors and identify patterns.
- Regular Link Checks: Consistently verify links on the website to ensure all resources are current and accessible.
Additionals Codes
Code | Description |
---|---|
404.0 | Not found - The requested file has been moved or does not exist. |
404.1 | Site Not Found - The requested website could not be found. |
404.2 | ISAPI or CGI restriction - The requested ISAPI or CGI resource is restricted. |
404.3 | MIME type restriction - The MIME mapping for the requested file extension is invalid or missing. |
404.4 | No handler configured - The file extension does not have an associated handler configured. |
404.5 | Denied by request filtering configuration - The requested URL contains a blocked character sequence. |
404.6 | Verb denied - The HTTP verb used in the request is not allowed. |
404.7 | File extension denied - The requested file extension is not permitted. |
404.8 | Hidden namespace - The requested directory is hidden from listing. |
404.9 | Files attribute hidden - The requested file is hidden. |
404.10 | Request header too long - The request was denied due to long headers. |
404.11 | Request contains double escape sequence - The request contains an invalid double escape sequence. |
404.12 | Request contains high-bit characters - High-bit characters are not allowed in the request. |
404.13 | Content length too large - The request exceeds the allowed content length. |
404.14 | Request URL too long - The requested URL exceeds the allowed length. |
404.15 | Query string too long - The query string in the request exceeds the allowed length. |
404.16 | WebDAV request sent to static file handler - A WebDAV request was sent to a static file handler. |
404.17 | Dynamic content mapped to static file handler - Dynamic content was incorrectly mapped to the static file handler. |
404.18 | Query string sequence denied - The query string contains a prohibited sequence. |
404.19 | Denied by filtering rule - The request was blocked by a filtering rule. |
404.20 | Too Many URL Segments - The requested URL contains too many segments. |
404.501 | Not found: concurrent request rate limit reached - Too many concurrent requests from the same IP. |
404.502 | Not found: maximum request rate limit reached - Maximum request rate reached for this IP. |
404.503 | Not found: IP address denied - IP address is denied access. |
404.504 | Not found: host name denied - Host name is on the deny list. |