WordPress除首页外所有页面均显示404,重置Permalink后问题反复出现
Hey Casey, sorry to hear you're stuck with this annoying 404 issue—having a quick fix that only lasts 1-2 days is incredibly frustrating. Let’s dig into the root causes and actionable steps to resolve this once and for all.
Why Saving Permalinks Fixes It (Temporarily)
First, let’s clarify what happens when you hit "Save Changes" on the Permalink settings page: WordPress regenerates its rewrite rules and updates the .htaccess file (for Apache servers) or validates Nginx rewrite configurations. When this fixes the problem temporarily, it means something is overwriting or corrupting these rewrite rules/settings after a day or two.
Step-by-Step Troubleshooting
1. Check for Server-Side .htaccess/Rewrite Rule Resets
Many hosting providers have automated tools (security scanners, cache purgers, or auto-config scripts) that can overwrite .htaccess without warning.
- Verify .htaccess permissions: Ensure the file has permissions set to
644—this balances security and allows WordPress to write to it when needed. - Backup and monitor .htaccess: After saving permalinks, copy the contents of
.htaccessto a backup file. When the 404s return, compare the current.htaccessto your backup. If it’s changed, check your hosting control panel logs or reach out to support to see what’s modifying the file. - Nginx users: If you’re on Nginx, confirm your server block includes the correct WordPress rewrite rules. Some hosts use automated config tools that can reset these rules—lock in the correct rules in your Nginx config file if possible.
2. Rule Out Custom Theme Conflicts
Since your site uses a custom theme, there might be code in it that’s interfering with rewrite rules over time.
- Test with a default theme: Temporarily switch to a default WordPress theme (like Twenty Twenty-Four) and monitor for 2-3 days. If the 404s don’t return, your custom theme is the culprit.
- Inspect theme code: Look in your theme’s
functions.phpfile or any custom scripts for:- Calls to
flush_rewrite_rules()that are triggered on a schedule (viawp_schedule_event). - Code that modifies the
permalink_structureorrewrite_rulesoptions in the database.
- Calls to
3. Investigate Plugin Issues (Even Unupdated Ones)
While you haven’t updated plugins recently, server environment changes (like hidden PHP/MySQL upgrades) can cause old plugins to misbehave.
- Disable plugins one by one: Disable each plugin, save permalinks, and monitor for a few days. If disabling a specific plugin stops the 404s, that plugin is conflicting with rewrite rules. You can either find an alternative, manually fix its code, or check if there’s a legacy update available (if safe).
- Check plugin cron jobs: Some plugins run scheduled tasks that might corrupt rewrite rules. Use a tool like WP Crontrol to review active cron jobs and look for any suspicious tasks linked to problematic plugins.
4. Fix Potential WordPress Core or Database Issues
Even without updates, core files can get corrupted, or database settings might be tampered with.
- Reinstall WordPress Core: Go to Dashboard → Updates, click "Reinstall Now"—this replaces core files without touching your theme, plugins, or content, fixing any corrupted files.
- Check database permalink settings: In your WordPress database (via phpMyAdmin), look at the
wp_optionstable for thepermalink_structureandrewrite_rulesentries. Save these values after fixing permalinks, then compare them when the 404s return. If they’ve changed, there’s code somewhere modifying these settings.
Temporary Workaround (While You Find the Root Cause)
If you need a quick fix to keep the site running, you can set up an automatic daily flush of rewrite rules. Add this code to your theme’s functions.php file or a custom plugin:
function auto_flush_rewrite_rules() { // Only flush if the current user has admin privileges (prevents unnecessary runs) if ( current_user_can( 'manage_options' ) ) { flush_rewrite_rules(); } } // Schedule the function to run daily if ( ! wp_next_scheduled( 'auto_flush_rewrite_hook' ) ) { wp_schedule_event( time(), 'daily', 'auto_flush_rewrite_hook' ); } add_action( 'auto_flush_rewrite_hook', 'auto_flush_rewrite_rules' );
This will automatically refresh permalinks once a day, preventing the 404s from appearing. Remember, this is a band-aid—focus on finding the root cause long-term.
Final Note on Security
I know you’re aware of the security risks from outdated plugins/themes. Once you resolve the 404 issue, consider updating plugins one at a time (testing after each update) to find which ones cause crashes, then replace those with maintained alternatives. It’s critical to keep your site secure to avoid bigger issues down the line.
内容的提问来源于stack exchange,提问作者Casey

