# HTTP 404 Not Found

**Code:** `404` · **Category:** HTTP · **Seen on:** Nginx, Apache, React, WordPress

The server can’t find anything at the requested URL.

## Meaning

A 404 means the server is reachable but there is no resource at that path. It may never have existed, it moved without a redirect, or the server’s routing isn’t sending the request to your application.

For single-page apps and frameworks with “pretty URLs”, a 404 on page refresh almost always means the web server isn’t rewriting unknown paths to `index.html` / `index.php`.

## Common causes

- Typo or wrong case in the URL (paths are case-sensitive on Linux)
- Page or file was moved/deleted without a 301 redirect
- Missing rewrite rules — SPA/framework routes 404 on refresh
- Wrong document root or base path (app deployed in a sub-folder)
- API route not registered, or wrong HTTP method mapped to a different route
- `.htaccess` not applied because `AllowOverride None`
- Some APIs return 404 instead of 403 to hide resources you can’t access

## Quick fix

1. Double-check the exact URL, including case and trailing slash
2. Add a fallback rewrite to `index.html` / `index.php` for SPA and framework routes
3. Confirm the server’s document root points to the right folder
4. For moved pages, add a 301 redirect from the old URL
5. List your framework’s registered routes (`php artisan route:list`, `rails routes`)

## Detailed fix by platform

### Nginx

1. Send unknown paths to your app:

```nginx
location / {
    try_files $uri $uri/ /index.html;          # SPA
    # try_files $uri $uri/ /index.php?$query_string;  # PHP frameworks
}
```


### Apache

1. Enable mod_rewrite (`sudo a2enmod rewrite`) and set `AllowOverride All` for the directory.
2. Front-controller fallback in `.htaccess`:

```apache
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]
```


### React

1. With React Router, configure the host to serve `index.html` for all routes (Netlify `_redirects`: `/* /index.html 200`; Vercel rewrites).
2. If deployed under a sub-path, set `basename` on the router and `homepage`/`base` in the build config.

### WordPress

1. Re-save Settings → Permalinks to regenerate rewrite rules.
2. Check that `.htaccess` is writable and mod_rewrite is enabled.

## Code examples

### Check how the server sees the path

```bash
curl -I https://example.com/dashboard
curl -I https://example.com/Dashboard   # case matters on Linux
```

## How to diagnose

1. **URL** — Exact path, case, trailing slash, sub-folder?
2. **Static file** — Does the file exist under the document root?
3. **Routing** — Does the web server rewrite to the app front controller?
4. **App routes** — Is the route registered for this method?
5. **History** — Was the page moved? Add a 301.

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/http/404-not-found)
