404 Not Found
Fault: Client
TL;DR
The URL you're trying to access doesn't exist on the server.
The server cannot find the requested resource.
What This Error Means
The server cannot find the requested resource.
The URL you're trying to access doesn't exist on the server.
Common Causes
- URL typo or incorrect link
- Resource deleted or moved
- Route not defined
- File doesn't exist
How to Fix It (For Visitors)
- Check URL for typos
- Use site search to find content
- Return to homepage
- Clear browser cache
How to Fix It (For Developers/Admins)
- Verify file exists on server
- Check route configuration
- Review URL rewrite rules
- Implement custom 404 page
- Check for broken links
Code Examples
Here's how to return a 404 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Not Found"}), 404
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(404).json({ message: 'Not Found' });
});
PHP
<?php
http_response_code(404);
header('Content-Type: application/json');
echo json_encode(['message' => 'Not Found']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(404)
json.NewEncoder(w).Encode(map[string]string{
"message": "Not Found",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Not Found");
return ResponseEntity.status(404).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 404
json message: 'Not Found'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7231 Section 6.5.4.