WordPress迁移后仅首页可访问其余返回404 - 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:
Step 1: Refresh WordPress Permalinks
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
.htaccessfile (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:
- Enable the rewrite module via terminal:
sudo a2enmod rewrite - Restart Apache to apply the change:
sudo systemctl restart apache2 - 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 changeAllowOverride NonetoAllowOverride 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:
- Open your Nginx site config file (typically
/etc/nginx/sites-available/your-site), and add this block inside theserversection:location / { try_files $uri $uri/ /index.php$is_args$args; } - Test the Nginx configuration to make sure there are no syntax errors:
sudo nginx -t - 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

