Fix WordPress posts returning 404 (pages OK)
If your WordPress posts are returning 404 errors while your pages load just fine, it can be a frustrating issue that disrupts your site’s functionality and user experience. The good news is this problem usually stems from permalink or rewrite rule issues, and you can fix it quickly by resetting your permalink structure or adjusting your server configuration.
Quick Fix
- Log in to your WordPress admin dashboard.
- Go to Settings > Permalinks.
- Without changing anything, click the Save Changes button at the bottom.
- Check your posts again; the 404 errors should be resolved.
Why this happens
This issue typically occurs because WordPress’s rewrite rules are out of sync or not properly flushed. WordPress uses rewrite rules to map URLs to the correct content. When these rules are corrupted, missing, or not updated, posts URLs can return 404 errors even though pages work fine.
Common causes include:
- Changing permalink settings without flushing rewrite rules.
- Server configuration changes or restrictions (e.g., missing .htaccess rules on Apache or incorrect Nginx configuration).
- Plugin conflicts that modify rewrite rules.
- File permission issues preventing WordPress from writing to the .htaccess file.
Step-by-step
1. Reset Permalinks in WordPress Dashboard
- Navigate to Settings > Permalinks.
- Click Save Changes without modifying any settings.
This action forces WordPress to flush and regenerate rewrite rules.
2. Check and Update .htaccess File (Apache)
If resetting permalinks doesn’t fix the issue, verify your .htaccess
file contains the correct WordPress rewrite rules.
# 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
Make sure the file is located in your WordPress root directory and is writable by the server.
3. Configure Nginx Rewrite Rules
If you use Nginx, WordPress permalinks require specific rewrite rules in your server configuration. Add or verify the following inside your server block:
location / {
try_files $uri $uri/ /index.php?$args;
}
After updating Nginx config, reload Nginx:
sudo nginx -s reload
4. Check File Permissions
Ensure .htaccess
(Apache) or your WordPress root directory files have correct permissions:
chmod 644 .htaccess
chmod 755 /path/to/wordpress/
Incorrect permissions can prevent WordPress from updating rewrite rules.
5. Disable Plugins Temporarily
Some plugins interfere with rewrite rules. Temporarily deactivate all plugins to check if the issue resolves:
wp plugin deactivate --all
If posts work after deactivation, reactivate plugins one by one to identify the culprit.
Works on
Environment | Notes |
---|---|
Apache | Requires correct .htaccess with WordPress rewrite rules. |
Nginx | Needs proper try_files directive in server block. |
LiteSpeed | Compatible with Apache-style .htaccess rules. |
cPanel / Plesk | Standard hosting control panels; ensure file permissions and rewrite modules enabled. |
FAQ
- Q: Why do pages work but posts return 404 errors?
- A: Pages often use static URLs that don’t rely on rewrite rules as heavily as posts. If rewrite rules are broken, posts URLs break but pages can still load.
- Q: Can a plugin cause posts to 404?
- A: Yes, plugins that modify URLs or rewrite rules can cause conflicts leading to 404 errors on posts.
- Q: How do I flush rewrite rules manually?
- A: Besides saving permalinks in the dashboard, you can add
flush_rewrite_rules();
in your theme’sfunctions.php
temporarily and then remove it after the rules flush. - Q: What if I don’t have access to .htaccess or Nginx config?
- A: Contact your hosting provider to ensure rewrite modules are enabled and configurations are correct.
- Q: Does changing permalink structure fix the issue?
- A: Sometimes changing and saving a different permalink structure forces rewrite rules to update and resolves 404 errors.