404 on Every Page Except the Homepage
This specific pattern — homepage fine, every other URL a 404 — means the server is not passing pretty permalinks to WordPress. The homepage works because it does not need a rewrite.
The short version
- Save Settings → Permalinks first. It fixes most cases.
- On Apache the cause is .htaccess or mod_rewrite.
- On Nginx it is the try_files directive.
- Set the default permalink structure temporarily if you cannot reach the admin.
1. Flush the rewrite rules
Go to Settings → Permalinks and click Save without changing anything. This regenerates the rules and, on Apache, rewrites .htaccess. It resolves this more often than anything else.
Or from the command line:
wp rewrite flush --hard
2. Apache: check .htaccess
The file must exist in the web root and contain the WordPress 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
If the file is missing, create it with that content and set it to 644. If it exists and saving permalinks does not update it, the file is not writable.
3. Apache: is mod_rewrite enabled?
apache2ctl -M | grep rewrite
# should print: rewrite_module (shared)
# if missing
a2enmod rewrite
systemctl restart apache2
Also confirm the virtual host allows overrides. If AllowOverride is None, your .htaccess is being ignored entirely:
<Directory /var/www/html>
AllowOverride All
</Directory>
4. Nginx: the try_files directive
Nginx does not read .htaccess. The rewrite must be in the server block:
location / {
try_files $uri $uri/ /index.php?$args;
}
Without that line, every URL that is not a real file returns 404. After editing, test and reload:
nginx -t && systemctl reload nginx
5. If you cannot reach the admin
Set the permalink structure to the plain default from wp-config.php so the admin becomes reachable, fix the server configuration, then set the structure back:
// temporary
define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );
Admin URLs do not depend on the rewrite rules, so /wp-admin should remain reachable even when every front-end URL 404s. If it is not, you have a different problem.
When only some pages 404
That is a different issue and not this one:
| Pattern | Likely cause |
|---|---|
| All pages except home | Rewrite rules — this post |
| Only a specific page | That page was deleted, or its slug changed |
| Only custom post types | Rewrite rules for that post type need flushing |
| Only category or tag archives | A slug conflict, or they are disabled |
| Only after a migration | Rewrite rules plus possibly a URL mismatch |
Common questions
Why does saving permalinks fix it?
It regenerates the rewrite rules and rewrites .htaccess. If the rules were stale or the file was missing, that is the whole fix.
It worked on the old host
Different web server, or AllowOverride is set differently. Check which server you are now on.
Do I need to redirect anything?
No. The URLs are correct; the server was not routing them. Nothing has changed from a visitor’s perspective once it works.
Sumit
Writes everything on TechMozz.