📑 Table of ContentsHide / Show
Why 404 Errors Occur Post-Migration
It is common after migrating WordPress to a new server to find that while the homepage loads properly, every internal blog post, page, and category throws a dreaded 404 Not Found error. This happens because web server rewrite rules in .htaccess were not generated or the web server configuration is ignoring directory rewrites.
Fix 1: The 10-Second Permalink Flush
The simplest and most effective fix requires zero code:
- Log in to your WordPress admin dashboard on the new server.
- Navigate to Settings → Permalinks.
- Do not change any settings; simply scroll to the bottom and click Save Changes.
- Click Save Changes a second time. This forces WordPress to regenerate its internal rewrite array and write fresh rewrite directives to your web server.
Fix 2: Manually Recreating .htaccess
If WordPress lacks write permissions to your root directory, create or edit the .htaccess file manually and paste the standard WordPress rewrite block:
# 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
Fix 3: Enabling mod_rewrite on VPS / Apache
If you manage your own Ubuntu or Debian VPS server, verify that the Apache rewrite module is enabled:
sudo a2enmod rewrite
sudo systemctl restart apache2
⚡ Related WordPress Migration & Hosting Guides
- How to Clone a WordPress Site to a Staging Environment – Test updates, themes, and plugins safely without risking live downtime.
- Step-by-Step WordPress Migration with Duplicator Plugin – Complete free & pro guide to package and deploy full WordPress databases.
- How to Change WordPress Domain Name & Fix Database URLs – Use search-replace tools to update URLs without serialization breaks.
- Top 7 Image Optimization Plugins for WordPress – Next-gen WebP & AVIF compression to pass Google PageSpeed audits.
Nginx Rewrite Directives & Automated 404 Monitoring
When migrating a WordPress site from an Apache host to a high-speed Nginx server (such as LEMP or RunCloud), the classic .htaccess file is completely ignored. As a consequence, while the homepage functions normally, clicking any blog post or category link produces an instant 404 Not Found error.
To resolve this on Nginx, ensure your site’s server configuration file contains the universal WordPress rewrite block inside the primary location directive:
# Essential Nginx WordPress Permalink Rewrite
location / {
try_files $uri $uri/ /index.php?$args;
}
After saving, test your configuration with sudo nginx -t and reload the service with sudo systemctl reload nginx. Additionally, deploy a lightweight 404 monitoring plugin like Redirection for the first 14 days post-migration to track and catch any orphaned backlink URLs.
Frequently Asked Questions
Why do blog posts show 404 errors while the homepage loads fine after migration?
The homepage is served directly by the web server index file, but custom permalinks require active rewrite rules (mod_rewrite in Apache or try_files in Nginx) to route dynamic requests to index.php.
How do I quickly flush WordPress rewrite rules without FTP or SSH access?
Simply log in to your WordPress dashboard, navigate to Settings → Permalinks, and click the blue “Save Changes” button at the bottom of the page without changing any settings.
Can aggressive caching plugins cause persistent 404 errors after domain transfer?
Yes. Outdated cached rewrite maps or old domain transients stored in Redis/Memcached will serve 404s until the object cache and page cache are completely purged.

