修改WordPress站点URL并迁移目录后出现404错误求助
Hey there, let’s work through this 404 issue together—this is a super common scenario when moving WordPress files and updating your site’s URL, so we’ll get your www.SiteB.com up and running smoothly. Here’s a step-by-step breakdown of what to check:
1. Ensure All Database URLs Are Updated
The WordPress backend URL change might not have covered every instance of your old URL in the database. Let’s fix that:
- Log into your hosting’s phpMyAdmin tool, select your WordPress database.
- Locate the
wp_optionstable (your table prefix might be different if you changed it during setup). Find thesiteurlandhomerows—double-check their values are set tohttps://www.SiteB.com(addhttpsif you use SSL). - To update old links in posts, pages, and metadata, run these SQL queries (replace
wp_with your actual table prefix):
Note: Always back up your database before running SQL queries!UPDATE wp_posts SET post_content = REPLACE(post_content, 'www.SiteA.com', 'www.SiteB.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'www.SiteA.com', 'www.SiteB.com');
2. Fix the .htaccess File in the Root Directory
When moving files from a subdirectory to the root, your old .htaccess might still have subdirectory-specific rules, or it might be missing entirely:
- First, back up your current
.htaccessfile (if it exists). - If you can access the WordPress admin dashboard: Go to Settings > Permalinks, select any permalink structure (even the one you already use) and click "Save Changes." This will generate a fresh, root-directory-friendly
.htaccessfile. - If you can’t access the dashboard: Create a new
.htaccessfile in your root directory with this content:# 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 - Set the file permissions to
644so your server can read it properly.
3. Verify Complete File Migration
Double-check that you moved all WordPress files and folders from the subdirectory to the root:
- Ensure
wp-admin,wp-includes,wp-content, and root files likewp-config.php,index.phpare all present in the root directory. - Open
wp-config.phpto confirm your database credentials (DB_NAME,DB_USER,DB_PASSWORD,DB_HOST) are still correct—sometimes file transfers can corrupt this file, so a quick check won’t hurt.
4. Clear All Caches
Old cached data is a frequent culprit for 404s after URL changes:
- Browser Cache: Force-refresh your browser with
Ctrl+Shift+R(Windows/Linux) orCmd+Shift+R(Mac), or clear your browser’s cache entirely. - Server/Plugin Cache: If you use a caching plugin (like WP Rocket, W3 Total Cache) or your host offers server-side caching (e.g., Redis, LiteSpeed), clear those caches too.
- CDN Cache: If you use a CDN, purge its cache to ensure it’s serving the new URL and content.
5. Confirm Domain & Hosting Configuration
Make sure your new domain is pointing to the right place:
- Check that
www.SiteB.comis correctly bound to your hosting account’s root directory (not the old subdirectory) in your hosting control panel. - Verify your DNS records for
www.SiteB.comare pointing to the correct server IP—you can useping www.SiteB.comin your terminal to check this.
6. Fix Admin Login Issues (If Persistent)
If you’re still having trouble logging into the backend, force the URL settings in wp-config.php:
- Add these lines to your
wp-config.phpfile (before the/* That's all, stop editing! Happy publishing. */line):define('WP_HOME','https://www.SiteB.com'); define('WP_SITEURL','https://www.SiteB.com'); - This bypasses the database settings temporarily. Once you can log in, go to Settings > General to confirm the URL settings are correct, then you can remove these lines (or leave them if you prefer).
Work through these steps in order, and your site should start loading correctly. If you hit any snags, let me know which step you’re stuck on!
内容的提问来源于stack exchange,提问作者Saint Augustine




