本地环境WordPress导航菜单失效及分页404问题求助
I’ve tackled quite a few similar WordPress local dev 404 issues before—let’s walk through practical steps to get your site back on track:
Verify your local server’s rewrite module is enabled
WordPress pretty permalinks rely on URL rewriting, which is often disabled by default in local environments.- For Apache: Check your
httpd.conffile to ensureLoadModule rewrite_module modules/mod_rewrite.soisn’t commented out. Also, make sure your site’s virtual host config hasAllowOverride Allset (instead ofNone) so.htaccessrules are applied. - For Nginx: Add or confirm this rule in your site’s config file to handle WordPress permalinks:
location / { try_files $uri $uri/ /index.php?$args; }
Don’t forget to restart your server after making these changes.
- For Apache: Check your
Resave your permalink settings (twice!)
Sometimes a single resave doesn’t properly regenerate rewrite rules. Head to WP Admin → Settings → Permalinks:- Switch to a different permalink structure (e.g., from "Post name" to "Day and name") and save.
- Switch back to your original preferred structure and save again.
This forces WordPress to rewrite the.htaccess(Apache) or trigger Nginx rule recognition.
Check your
.htaccessfile (Apache only)
Ensure the.htaccessfile exists in your site’s root directory and has the correct WordPress rewrite rules. If it’s missing, create it and paste this:# 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 WordPressMake sure the file has proper read/write permissions for your local server.
Confirm your site URL settings are correct
Go to WP Admin → Settings → General and double-check that both "WordPress Address (URL)" and "Site Address (URL)" match your local development URL (e.g.,http://localhost/your-siteorhttp://your-local-site.test). Mismatched URLs often break permalink routing.Disable plugins to rule out conflicts
SEO, caching, or custom post type plugins can sometimes interfere with rewrite rules. Disable all plugins, then test your navigation links. If they work, re-enable plugins one by one to find the culprit.Switch to a default theme
Custom themes may have faulty rewrite rules or broken template logic. Switch to a default theme like Twenty Twenty-Four and test. If the 404s go away, you’ll need to debug your theme’sfunctions.phpfile (look for custom rewrite rules) or check how it generates navigation links.
If none of these steps work, check your local server’s error logs—they’ll often give specific clues about what’s blocking the rewrite rules.
内容的提问来源于stack exchange,提问作者Don Macarthur

