HTTP 404 Not Found

The server cannot find the resource at the URL you requested. The page, file, or API endpoint either does not exist, was deleted, or the URL contains a typo. This is the most common HTTP error encountered on the web.

What Is HTTP 404 Not Found?

HTTP 404 Not Found is the most recognized status code on the web. It indicates that the server was reached successfully but could not locate the resource at the requested URL. The server does not indicate whether the absence is temporary or permanent. If the server knows the resource has been permanently removed, it should return 410 Gone instead of 404. A 404 simply means "I cannot find what you are looking for at this address right now."

For website owners, 404 errors have significant implications for both user experience and search engine optimization. When users encounter a 404 page, they often leave the site entirely. When search engine crawlers encounter 404 errors, they eventually remove the URL from their index and may interpret frequent 404s as a sign of poor site quality. This is why monitoring for 404 errors, implementing redirects for moved content, and designing helpful custom 404 pages are standard practices in web development.

In API development, 404 serves a different purpose. It tells the client that the specific resource they requested does not exist in the data store. For instance, GET /api/users/9999 returns 404 if user 9999 does not exist. Well-designed APIs return descriptive error messages with their 404 responses, helping developers quickly understand what went wrong. Some security-sensitive APIs return 404 instead of 403 to avoid revealing whether restricted resources exist.

Common Causes

Typo in URL

A misspelled URL path, incorrect capitalization, or missing path segment. Even a single character difference can cause a 404 since URLs are case-sensitive on most servers.

Deleted or Moved Content

The page or resource existed previously but was removed or moved to a new URL without a redirect. External links and bookmarks pointing to the old URL now result in 404 errors.

Incorrect API Endpoint

The API route does not match any defined endpoint. This can be caused by a wrong version prefix, missing path segments, or using the wrong HTTP method on a route that exists for a different method.

Broken Internal Links

Links within your website point to pages that no longer exist due to restructuring, CMS changes, or content removal. These broken links create a poor user experience and hurt SEO.

How to Fix

Check the URL for Typos

Carefully review the URL path for misspellings, incorrect capitalization, missing slashes, or extra characters. Compare it against the working URL from documentation or navigation.

Implement 301 Redirects

When moving or renaming pages, set up 301 permanent redirects from the old URL to the new one. This preserves SEO value and ensures existing links continue to work.

Create a Custom 404 Page

Design a helpful 404 page that includes a search bar, links to popular pages, and a clear message. A well-designed 404 page can retain users who would otherwise leave your site.

Audit with Crawl Tools

Use site crawling tools to find all broken internal links across your website. Fix each broken link by updating the href to the correct URL or removing the link entirely.

Code Examples

Express.js

// Express.js — custom 404 handler with logging
const express = require('express');
const app = express();

// API routes
app.get('/api/users/:id', async (req, res) => {
  const user = await User.findById(req.params.id);
  if (!user) {
    return res.status(404).json({
      error: 'Not Found',
      message: `User with ID ${req.params.id} does not exist`
    });
  }
  res.json(user);
});

// Custom 404 page for HTML requests
app.use((req, res) => {
  // Log the 404 for monitoring
  console.warn(`404: ${req.method} ${req.originalUrl} from ${req.ip}`);

  if (req.accepts('html')) {
    res.status(404).sendFile('404.html', { root: './public' });
  } else {
    res.status(404).json({
      error: 'Not Found',
      message: `${req.method} ${req.path} does not exist`,
      suggestion: 'Check the URL and try again'
    });
  }
});

Flask (Python)

# Flask — custom 404 handler with logging
from flask import Flask, jsonify, request, render_template
import logging

app = Flask(__name__)
logger = logging.getLogger(__name__)

@app.route('/api/users/<int:user_id>', methods=['GET'])
def get_user(user_id):
    user = User.query.get(user_id)
    if user is None:
        return jsonify(
            error='Not Found',
            message=f'User with ID {user_id} does not exist'
        ), 404
    return jsonify(user.to_dict())

@app.errorhandler(404)
def not_found(error):
    # Log the 404 for monitoring
    logger.warning(f'404: {request.method} {request.path} from {request.remote_addr}')

    if request.accept_mimetypes.best == 'text/html':
        return render_template('404.html'), 404

    return jsonify(
        error='Not Found',
        message=f'{request.method} {request.path} does not exist',
        suggestion='Check the URL and try again'
    ), 404

Frequently Asked Questions

What causes a 404 error?

A 404 error occurs when the server cannot find the resource at the requested URL. Common causes include typos in the URL, deleted pages, moved content without redirects, broken links, and incorrect API endpoints.

What is the difference between 404 and 410?

HTTP 404 means the resource was not found and the server does not know if the absence is temporary or permanent. HTTP 410 Gone means the resource was deliberately deleted and will not be available again. Search engines remove 410 URLs from their index faster than 404 URLs.

Do 404 errors hurt SEO?

A few 404 errors are normal and do not hurt SEO. However, many 404 errors, especially for pages that had backlinks, can negatively impact your site's search rankings. Implement 301 redirects for moved content to preserve SEO value.

Should my API return 404 or an empty array?

For collection endpoints like GET /api/users, return 200 with an empty array when no results match. For single resource endpoints like GET /api/users/123, return 404 when the specific resource does not exist.

How do I create a good custom 404 page?

Include a clear message that the page was not found, a search bar, links to popular pages, and your site navigation. Use a friendly tone and consider adding a link to your homepage. Avoid generic error messages.

Monitor Your APIs & Services

Get instant alerts when your endpoints go down. 60-second checks, free forever.

Start Monitoring Free →