迁移主机后WordPress网站异常求助(含.htaccess重写配置说明)
Hey there, let’s walk through troubleshooting your post-migration issues step by step—your setup (WP in /site subdirectory, root domain access, WP Fastest Cache, and custom /labs rewrite rules) has a few moving parts, so we’ll tackle each one systematically.
1. First: Validate Core WordPress & Directory Configs
These are the most common pain points after migration:
- Double-check Site URL settings:
Head to WP Admin > Settings > General. Ensure:- WordPress Address (URL):
https://example.com/site - Site Address (URL):
https://example.com
If you can’t access the admin, add these lines to yourwp-config.phpfile (in the/sitedirectory) to force the correct values:
define('WP_HOME','https://example.com'); define('WP_SITEURL','https://example.com/site'); - WordPress Address (URL):
- Audit .htaccess files across directories:
- Root directory .htaccess: Make sure it forwards non-
/labstraffic to the/sitesubdirectory without breaking your custom rules. Example:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # Skip /labs directory from WP forwarding RewriteCond %{REQUEST_URI} !^/labs/ # Forward all other non-file/non-directory requests to WP RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /site/index.php [L] </IfModule> - /site directory .htaccess: Keep the default WordPress rewrite rules, and ensure they don’t conflict with WP Fastest Cache later:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /site/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /site/index.php [L] </IfModule> - /labs directory .htaccess: Confirm your custom rules are intact and take priority. Add
RewriteBase /labs/to ensure the rules apply correctly to that subdirectory.
- Root directory .htaccess: Make sure it forwards non-
2. Fix WP Fastest Cache Post-Migration Glitches
Cache plugins often hold onto old host paths or settings—let’s reset this:
- Purge all cached content: Go to WP Admin > WP Fastest Cache, click Delete Cache and Delete Minified CSS/JS to wipe all old cached files from the new server.
- Temporarily disable the plugin: If the site works with WP Fastest Cache off, the issue is a misconfiguration. Re-enable it and:
- Add
/labs/to the Exclude list under Cache Settings to avoid caching that directory. - For Apache hosts, ensure the Rewrite Rules toggle is on; for Nginx hosts, copy the plugin-generated Nginx rules into your server’s config file (check your host’s docs for where to place this).
- Add
- Check file permissions: Make sure the
/site/wp-content/cachedirectory has proper read/write permissions for the server user—set directories to755and files to644if needed.
3. Server-Level Checks for the New Host
- Verify SSL coverage: Ensure your SSL certificate is valid for
example.comand all subdirectories. Visit bothhttps://example.comandhttps://example.com/labsto confirm no certificate errors appear in the browser. - Enable required modules: For Apache hosts, confirm
mod_rewriteis enabled. For Nginx hosts, double-check that your server config has location blocks handling both WordPress and/labstraffic correctly. - Match PHP environment: Ensure the new host’s PHP version is compatible with your WordPress version (minimum 7.4 recommended). Use WP Admin > Tools > Site Health to check for missing extensions (like
mysqliorcurl) that might cause errors.
4. Test Edge Cases to Pinpoint Issues
- Test
/labsdirect access: Visithttps://example.com/labs—if it redirects to a WordPress 404, your root.htaccessrule isn’t excluding/labsproperly. Double-check theRewriteCond %{REQUEST_URI} !^/labs/line for typos. - Refresh permalinks: Go to WP Admin > Settings > Permalinks and click Save Changes (no need to edit anything). This refreshes WordPress rewrite rules, which often fixes broken post/page links after migration.
- Test admin access: Visit
https://example.com/site/wp-admin—if you can’t log in, clear your browser cache/cookies, or temporarily disable WP Fastest Cache to rule out cache interference.
内容的提问来源于stack exchange,提问作者Emil
相关产品推荐
相关产品推荐

