← Back to Chapters

404 Not Found

? 404 Not Found

? Quick Overview

The 404 Not Found status code is an HTTP response sent by a server when the requested resource cannot be found. It means the server is reachable, but the specific URL or file does not exist.

? Key Concepts

  • Client-side error (4xx category)
  • Resource does not exist on the server
  • URL may be incorrect, deleted, or moved
  • Server is working correctly

? Syntax / Theory

When a browser requests a URL, the server searches for the requested resource. If it cannot locate the file or route, it responds with status code 404.

  • Status Line: HTTP/1.1 404 Not Found
  • No authentication issue
  • No server crash

? Code Example(s)

? View Code Example
// Example of sending a 404 response using Node.js
res.status(404).send("Page not found");
? View Code Example
// PHP example for returning a 404 status code
http_response_code(404);
echo "404 - Page Not Found";

? Live Output / Explanation

What Happens?

The browser displays a 404 error page. This may be a default server page or a custom-designed error page created by the developer.

? Interactive Example

Use the simulator below to send requests to a fake server and see the status code response:

Waiting for request...
 
? View Static Code Logic
// Visiting a missing route like this will trigger a 404
https://example.com/this-page-does-not-exist

? Use Cases

  • Handling broken or outdated links
  • Displaying custom error pages
  • Improving SEO by properly signaling missing pages
  • User-friendly navigation fallback

✅ Tips & Best Practices

  • Create custom 404 pages with helpful navigation
  • Log 404 errors to identify broken links
  • Avoid redirecting all 404s to the homepage
  • Return correct HTTP status codes

? Try It Yourself

  • Create a custom 404 HTML page
  • Configure 404 handling in Apache or Nginx
  • Return 404 from a backend API
  • Test missing routes in your application