You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress迁移后仅首页可访问其余返回404 - DigitalOcean Droplet问题

Fixing WordPress 404 Errors (Except Homepage) After Migration to DigitalOcean Droplet

Hey Brandon, let’s work through that frustrating 404 issue you’re dealing with post-migration. This is one of the most common hiccups when moving a WordPress site, and it’s almost always tied to permalink settings or server rewrite rules. Here’s how to get your pages loading properly:

This is the quickest fix and often solves the problem right away:

  • Log into your WordPress admin dashboard
  • Navigate to Settings → Permalinks
  • You don’t need to change any existing settings—just click the Save Changes button. This forces WordPress to regenerate its rewrite rules and update the .htaccess file (if you’re using Apache).

Step 2: Verify Apache Rewrite Module & Configuration (If Using Apache)

If refreshing permalinks didn’t work, check that Apache’s rewrite module is enabled and your site allows overrides:

  1. Enable the rewrite module via terminal:
    sudo a2enmod rewrite
    
  2. Restart Apache to apply the change:
    sudo systemctl restart apache2
    
  3. Open your site’s Apache virtual host config file (usually located at /etc/apache2/sites-available/your-site.conf), find the <Directory /var/www/root/public_html> section, and change AllowOverride None to AllowOverride All. Save the file, then restart Apache again.

Step 3: Add Rewrite Rules for Nginx (If Using Nginx)

If your Droplet uses Nginx instead of Apache, WordPress needs explicit rewrite rules to handle permalinks:

  1. Open your Nginx site config file (typically /etc/nginx/sites-available/your-site), and add this block inside the server section:
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    
  2. Test the Nginx configuration to make sure there are no syntax errors:
    sudo nginx -t
    
  3. If the test passes, restart Nginx:
    sudo systemctl restart nginx
    

Step 4: Double-Check .htaccess Permissions (Apache Only)

Ensure your .htaccess file has the correct ownership and permissions:

sudo chown www-data:www-data /var/www/root/public_html/.htaccess
sudo chmod 644 /var/www/root/public_html/.htaccess

Quick Note

More often than not, the permalink refresh alone fixes this issue. The problem happens because WordPress’s internal rewrite rules don’t automatically sync with the new server environment after migration. If you switched server types (e.g., from Apache to Nginx) during the move, you’ll definitely need to update the server’s rewrite rules as outlined above.

内容的提问来源于stack exchange,提问作者Brandon Benefield

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:19:27