Fix WordPress 404 Errors: Practical Troubleshooting Workflow

and user-visible…

WordPress “404 Not Found” errors can be some of the most frustrating to diagnose because they often hide the underlying server or database problem. This guide provides a systematic, professional workflow for identifying and fixing these issues.

The Difference Between a WP-404 and a Server-404

  • WP-404: Your site is loaded, but WordPress can’t find the content. This is usually a database or slug issue.
  • Server-404: The server itself (Apache or Nginx) doesn’t even know WordPress exists at that URL. This is often an `.htaccess` or file permission error.

1. The Quickest Fix: Refresh Your Permalinks

If your 404s appear after changing a plugin or moving your site, the first step is always to flush the permalink cache:

  1. Go to **Settings > Permalinks** in your WP Admin.
  2. Simply click **”Save Changes”** without changing anything. This forces WordPress to rebuild the internal redirect rules.

2. Verify the .htaccess File (Apache Only)

If refreshing permalinks doesn’t work, your `.htaccess` file might be corrupted or lack write permissions. Ensure it contains the standard WordPress block:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Note: On Nginx, these rules must be handled in your server config (`nginx.conf`), as Nginx does not use `.htaccess` files.

3. Check for File Permission Issues

Sometimes the 404 is caused because the web server doesn’t have permission to read the files it’s looking for:

  • Directories should generally be **755**.
  • Files should generally be **644**.
  • Ensure the `www-data` user (on most Linux systems) owns the WordPress directory.

4. Use WP-CLI to Find Broken Slugs

# List all published posts to check for slug mismatches
sudo -u www-data wp post list --post_status=publish --fields=ID,post_name,post_status

5. Review the Apache/Nginx Error Logs

The logs are the ultimate source of truth. They will tell you exactly what file or path the server was looking for when the 404 occurred:

# Watch for 404s in real-time
sudo tail -f /var/log/apache2/error.log | grep "404"

Further reading: Official WordPress .htaccess Documentation

Leave a Reply

Your email address will not be published. Required fields are marked *