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)
- Resave Permalinks: Go to Settings → Permalinks and click Save Changes (no edits needed). This flushes rewrite rules.
- Clear Caches: Purge plugin cache (e.g., W3TC, LiteSpeed), server/Varnish, and CDN (e.g., Cloudflare).
- 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/), setRewriteBase /blog/and the final rule to/blog/index.php. - Verify
AllowOverride All(so.htaccessrules are honored) and thatmod_rewriteis 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:
rewriteargs are set when registering the CPT, e.g.'rewrite' => ['slug' => 'portfolio'].has_archiveis 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)andSite Address (URL). - If you can’t access admin, define in
wp-config.phptemporarily:define('WP_HOME', 'https://example.com'); define('WP_SITEURL', 'https://example.com');
Theme/Plugin Conflicts
- Temporarily switch to a default theme (e.g., Twenty Twenty-Five).
- Deactivate plugins, then reactivate one by one—focus on redirect, security, multilingual, and caching plugins.
- Check
wp-content/debug.logfor fatal errors affecting rewrite bootstrap.
File and Directory Permissions
- Typical: Folders
755, files644. Ensure web server can read the root andindex.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
.htaccessor NGINXtry_filesand 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
- Resave permalinks; purge all caches.
- Restore default rewrite rules (
.htaccess/ NGINXtry_files/ IISweb.config). - Flush via WP-CLI if needed.
- Verify Site/Home URL and plugin/theme conflicts.
- Check CPT registration and flush after changes.
- 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.
👉 Need more help? Explore our WordPress Troubleshooting Guide for step-by-step solutions to the most common errors.