How to Fix WordPress 404 Page Not Found Error

What Is the WordPress 404 Page Not Found Error?

A WordPress 404 error means the server can’t find the page you’re trying to access. You’ll see messages like:

  • “404 Not Found”
  • “The page you are looking for doesn’t exist”
  • “Oops! That page can’t be found”

Unlike other errors, 404s don’t mean your site is broken. They simply indicate that WordPress doesn’t know how to route the URL you requested. This commonly happens after changing permalink settings, migrating your site, or when WordPress’s URL rewrite rules stop working properly.

The homepage might load perfectly while all other pages—posts, categories, custom post types—return 404 errors. This is the most telling symptom that your permalink structure has broken.


Common Causes of 404 Errors

  • Corrupted .htaccess file — Rewrite rules are missing or damaged
  • Permalink settings changed — You modified URL structure without regenerating rules
  • Site migration issues — Moving sites breaks URL configurations
  • Plugin conflicts — SEO or caching plugins interfering with URL routing
  • Missing index.php — WordPress’s main routing file was deleted
  • Incorrect file permissions — WordPress can’t read/write .htaccess
  • Server configuration issues — mod_rewrite module disabled on Apache
  • Custom post type registration — Custom URLs not flushed after adding new post types

This is the fastest fix and resolves most 404 errors instantly.

  1. Log in to WordPress admin (yoursite.com/wp-admin)
  2. Go to Settings → Permalinks
  3. Note your current permalink structure (you’ll set it back)
  4. Click on “Plain” temporarily
  5. Click “Save Changes”
  6. Now select your original structure (usually “Post name”)
  7. Click “Save Changes” again

WordPress regenerates the .htaccess rewrite rules. Test your site—404 errors should be gone.

Why this works: WordPress rewrites URLs internally but stores routing rules in .htaccess. When these rules get corrupted or deleted, WordPress can’t match URLs to content. Resaving permalinks regenerates clean rules.


Solution 2: Manually Check and Fix .htaccess

If resetting permalinks doesn’t work, the .htaccess file might be corrupted or missing.

Via FTP:

  1. Connect to your site via FTP
  2. Navigate to your WordPress root directory
  3. Look for .htaccess (enable “Show hidden files” in your FTP client)
  4. Download a backup copy to your computer

If .htaccess exists but is corrupted:

Delete it and create a new one with this default WordPress content:

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

If .htaccess is missing:

Create it via FTP and add the code above. Then go to WordPress admin → Settings → Permalinks → Save Changes to finalize.


Solution 3: Check File Permissions on .htaccess

WordPress needs proper permissions to read and write .htaccess.

Correct permissions:

  • .htaccess file: 644

Via FTP:

  1. Right-click .htaccess
  2. Select “File Permissions” or “Change Permissions”
  3. Enter 644 or check: Owner (Read, Write), Group (Read), Public (Read)
  4. Click OK

Via SSH:

cd /home/username/public_html
chmod 644 .htaccess

After fixing permissions, go to Settings → Permalinks → Save Changes to regenerate rules.


Solution 4: Enable mod_rewrite on Apache

WordPress permalinks require the Apache mod_rewrite module. If it’s disabled, all pages except the homepage will show 404 errors.

Check if mod_rewrite is enabled:

Create a file named test-rewrite.php:

<?php
if (in_array('mod_rewrite', apache_get_modules())) {
    echo "mod_rewrite is enabled";
} else {
    echo "mod_rewrite is NOT enabled";
}
?>

Visit yoursite.com/test-rewrite.php. If it says “NOT enabled,” contact your hosting provider to enable it.

On your own server (VPS/dedicated):

sudo a2enmod rewrite
sudo systemctl restart apache2

Delete test-rewrite.php after testing.


Solution 5: Check WordPress Address Settings

Incorrect site URL settings cause 404 errors on all pages.

  1. Go to Settings → General
  2. Check “WordPress Address (URL)” and “Site Address (URL)”
  3. Both should match, usually:
    • https://yourdomain.com (or with www if you use it)
  4. If they’re different or wrong, update them
  5. Click “Save Changes”

Can’t access wp-admin? Edit via database:

  1. Access phpMyAdmin from cPanel
  2. Select your WordPress database
  3. Open the wp_options table
  4. Find row with option_name = siteurl
  5. Update option_value to your correct site URL
  6. Do the same for option_name = home

Solution 6: Flush Rewrite Rules via Code

If the permalink reset doesn’t work through the dashboard, force it via code.

Method 1: Add to theme’s functions.php temporarily:

function custom_flush_rewrite_rules() {
    flush_rewrite_rules();
}
add_action('init', 'custom_flush_rewrite_rules');

Visit your site once, then remove this code immediately. Don’t leave it—flushing on every page load impacts performance.

Method 2: Via wp-cli (if available):

wp rewrite flush

This is the cleanest method if you have SSH access and wp-cli installed.


Solution 7: Disable Plugins Temporarily

A plugin might be interfering with WordPress’s URL routing.

Via WordPress admin:

  1. Go to Plugins → Installed Plugins
  2. Deactivate all plugins
  3. Test your site
  4. If 404s disappear, reactivate plugins one by one to find the culprit

Via FTP (if locked out):

  1. Navigate to /wp-content/plugins/
  2. Rename plugins folder to plugins-disabled
  3. Test your site
  4. If it works, rename back to plugins and test individual plugins

Common plugin culprits:

  • SEO plugins (Yoast, Rank Math) with broken rewrite rules
  • Caching plugins with aggressive settings
  • Custom post type plugins not registering URLs properly

Solution 8: Switch to Default Theme

Theme conflicts can cause 404 errors, especially with custom post types.

Via WordPress admin:

  1. Go to Appearance → Themes
  2. Activate a default WordPress theme (Twenty Twenty-Three, etc.)
  3. Test your site

Via FTP:

  1. Navigate to /wp-content/themes/
  2. Rename your active theme folder (e.g., mytheme → mytheme-disabled)
  3. WordPress automatically activates a default theme

If 404s disappear, your theme has a routing conflict. Contact the theme developer.


Solution 9: Check Custom Post Type Registration

If only custom post types return 404 errors, their rewrite rules weren’t registered properly.

Add this to your theme’s functions.php or custom post type plugin:

function fix_custom_post_type_permalinks() {
    // Replace 'my_custom_post_type' with your actual post type slug
    $post_type = 'my_custom_post_type';
    
    if (post_type_exists($post_type)) {
        flush_rewrite_rules(false);
    }
}
add_action('init', 'fix_custom_post_type_permalinks');

Visit your site once, then remove this code. Better yet, use this command if you have wp-cli:

wp rewrite flush --hard

Solution 10: Check Nginx Configuration (If Not Using Apache)

If your server runs Nginx instead of Apache, .htaccess doesn’t work. You need Nginx rewrite rules.

Add this to your Nginx configuration file (usually at /etc/nginx/sites-available/yourdomain):

location / {
    try_files $uri $uri/ /index.php?$args;
}

Then reload Nginx:

sudo systemctl reload nginx

Contact your hosting provider if you don’t have access to Nginx configs.


Prevention Tips

  • Don’t manually edit .htaccess unless necessary
  • Always flush permalinks after adding custom post types
  • Keep backup copies of working .htaccess files
  • Test theme and plugin updates on staging before production
  • Verify site URLs are correct after migrations
  • Use version control to track .htaccess changes
  • Document any custom rewrite rules you add

Personal note: I keep a “last known good” copy of .htaccess saved locally for every site I manage. When 404s pop up unexpectedly, I can compare the current version to my backup and spot exactly what changed. This has saved me hours of debugging over the years.

Related: If you’re experiencing other WordPress errors alongside 404s, check How to Fix WordPress 500 Internal Server Error or How to Fix WordPress 403 Forbidden Error for additional troubleshooting methods.


Conclusion

WordPress 404 errors almost always come from broken permalink settings or corrupted .htaccess files. The fix is usually just a matter of going to Settings → Permalinks and clicking Save Changes. If that doesn’t work, regenerating a clean .htaccess file solves the issue 95% of the time. The important thing is understanding that 404s don’t mean your content is gone—WordPress just lost the routing map and needs you to regenerate it.

Leave a Comment