You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

修改WordPress站点URL并迁移目录后出现404错误求助

Fixing WordPress 404 Errors After URL Change & Root Directory Migration

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_options table (your table prefix might be different if you changed it during setup). Find the siteurl and home rows—double-check their values are set to https://www.SiteB.com (add https if you use SSL).
  • To update old links in posts, pages, and metadata, run these SQL queries (replace wp_ with your actual table prefix):
    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');
    
    Note: Always back up your database before running SQL queries!

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 .htaccess file (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 .htaccess file.
  • If you can’t access the dashboard: Create a new .htaccess file 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 644 so 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 like wp-config.php, index.php are all present in the root directory.
  • Open wp-config.php to 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) or Cmd+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.com is 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.com are pointing to the correct server IP—you can use ping www.SiteB.com in 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.php file (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

火山引擎 最新活动