WordPress 404 Error: How to Fix Broken Permalinks

September 7, 2025
WordPress 404 Error: How to Fix Broken Permalinks

If your posts, pages, or custom post types return a 404 error while the WordPress admin still works, your permalink rules are likely broken. This guide shows quick fixes and deeper diagnostics for Apache, NGINX, and more.

Quick Fixes (Try These First)

  1. Resave Permalinks: Go to Settings → Permalinks and click Save Changes (no edits needed). This flushes rewrite rules.
  2. Clear Caches: Purge plugin cache (e.g., W3TC, LiteSpeed), server/Varnish, and CDN (e.g., Cloudflare).
  3. Disable Redirect/SEO Plugins Temporarily: Redirect loops or custom rules can force 404s.

Fix for Apache: Restore Default .htaccess

Ensure your site root contains a writable .htaccess. Replace its contents with the default WordPress rules, then resave permalinks:

# 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
  • For subdirectory installs (e.g., /blog/), set RewriteBase /blog/ and the final rule to /blog/index.php.
  • Verify AllowOverride All (so .htaccess rules are honored) and that mod_rewrite is enabled.

Fix for NGINX: Use try_files

NGINX ignores .htaccess. Add this to your server block and reload NGINX:

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

Also ensure PHP location blocks and fastcgi params are correct. After updating, flush permalinks again in the WP admin.

Fix for IIS (web.config)

On IIS, confirm your web.config includes rewrite rules like:

<rule name="WordPress" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="index.php" />
</rule>

WP-CLI: Flush Rewrite Rules

When you can’t access the admin or for scripted repairs:

wp rewrite flush --hard
# Optional: set a specific structure then flush
wp option update permalink_structure '/%postname%/'
wp rewrite flush --hard

Custom Post Types 404 (CPT Only)

If only CPT archives/singles 404 after adding or changing a custom post type, ensure:

  • rewrite args are set when registering the CPT, e.g. 'rewrite' => ['slug' => 'portfolio'].
  • has_archive is correct if you expect an archive.
  • Flush rewrite rules after registering (visit Permalinks or call flush_rewrite_rules() once on activation).

Mixed/Site URL Mismatch

Wrong URLs can break routing and force 404s:

  • Check Settings → General: WordPress Address (URL) and Site Address (URL).
  • If you can’t access admin, define in wp-config.php temporarily:
    define('WP_HOME', 'https://example.com');
    define('WP_SITEURL', 'https://example.com');
    

Theme/Plugin Conflicts

  1. Temporarily switch to a default theme (e.g., Twenty Twenty-Five).
  2. Deactivate plugins, then reactivate one by one—focus on redirect, security, multilingual, and caching plugins.
  3. Check wp-content/debug.log for fatal errors affecting rewrite bootstrap.

File and Directory Permissions

  • Typical: Folders 755, files 644. Ensure web server can read the root and index.php.
  • If WordPress can’t write .htaccess, you must edit it manually or fix ownership/permissions.

Multisite Notes

  • Subdirectory vs subdomain networks require different rewrite rules—use the rules generated during network setup.
  • Network-activated redirect/security plugins can cause global 404s—test by deactivating network-wide.

Edge Cases

  • Only the homepage works: Usually missing rewrite rules—restore .htaccess or NGINX try_files and flush.
  • Category/tag base changed: After changing bases, flush permalinks and verify no redirect plugin rewrites to the old base.
  • Multilingual plugins (WPML/Polylang): Re-save language URL settings; clear their caches and regenerate .htaccess if they manage it.

Troubleshooting Checklist

  1. Resave permalinks; purge all caches.
  2. Restore default rewrite rules (.htaccess / NGINX try_files / IIS web.config).
  3. Flush via WP-CLI if needed.
  4. Verify Site/Home URL and plugin/theme conflicts.
  5. Check CPT registration and flush after changes.
  6. Fix permissions so WordPress can write rules.

Once rewrite rules are correct and caches are cleared, 404 errors from broken permalinks should disappear across posts, pages, and custom post types.

Avatar

Written by

satoshi

I’ve been building and customizing WordPress themes for over 10 years. In my free time, you’ll probably find me enjoying a good football match.