Skip to content

How to Fix HTTP 404 Not Found Error

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Fix HTTP 404 Not Found Error. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

Your API client receives:

HTTP/1.1 404 Not Found

Or:

404 Not Found: The requested resource could not be found on the server.

The server cannot map the request URL to any existing resource or route.

Quick Fix

1. Verify the URL path

A typo or wrong case in the URL path causes 404:

// Wrong — typo in path
fetch('/api/userss/1')

// Right — correct path
fetch('/api/users/1')

Check the exact path from the API documentation. Many APIs are case-sensitive:

GET /api/users     (works)
GET /api/Users     (404)

2. Check route parameters

Route parameters must be valid:

// Wrong — missing required path parameter
fetch('/api/users/')

// Wrong — non-existent resource
fetch('/api/users/99999')  // user 99999 does not exist

// Right
fetch('/api/users/1')

3. Check query parameters

Some APIs return 404 for invalid query parameter combinations:

// Wrong — filter value that does not match any resource
fetch('/api/products?category=nonexistent')

// Check if the query is implemented by the API
fetch('/api/products?category=electronics')  // try known values

4. Check the HTTP method

The URL may exist but not for the method you are using:

// The endpoint exists for GET but not POST
// Wrong
fetch('/api/users/1', { method: 'POST' })

// Right
fetch('/api/users/1')  // GET

5. Check proxy and rewrite rules

Nginx or another reverse proxy may not route the path correctly:

# Nginx location block missing
location /api/ {
    proxy_pass http://backend:3000;
}
# Wrong — no trailing slash
location /api {
    proxy_pass http://backend:3000;
}

Check the proxy access logs for the actual upstream URL being requested.

6. Debug with curl

# Test the exact URL
curl -v https://api.example.com/api/users/1

# Check for redirects
curl -vL https://api.example.com/api/users/1

Prevention

  • Use consistent URL naming conventions (lowercase, kebab-case).
  • Document every API route with its exact path and method.
  • Use a REST client to test endpoints during development.
  • Log 404 errors with the full URL and method in production.
  • Set up a catch-all route handler to log unregistered paths.

Common Mistakes with 404 not found

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world API code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why do I get 404 for a URL that exists in the API docs?

The API may have changed without updating the docs, or the server may be running a different version. Check the actual server code or the API version in the URL.

What is the difference between 404 and 410 Gone?

404 means the resource does not exist (may never have existed). 410 Gone means the resource existed but was intentionally removed and will not return.

Can a 404 be caused by a missing Accept header?

Some APIs return 404 when the Accept header does not match the available content types. Ensure the client sends Accept: application/json or whatever the API expects.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro