Ffile2fix
Sign in Get started

How to fix WordPress 404 on all pages except the homepage

404 Not Found on every page except the homepage (WordPress permalinks)

With pretty permalinks, every URL must be rewritten to index.php by the web server. If the homepage loads but every other URL returns the server's own 404 page, the rewrite rules are missing or not being applied.

Also appears as: Not Found. The requested URL was not found on this server. · WordPress posts and pages return 404 but homepage works · 404 after migration / after changing permalink structure

Common causes

  • The .htaccess file is missing or lacks the WordPress rewrite block (common after migration)
  • Apache AllowOverride is set to None, so .htaccess is ignored
  • mod_rewrite is not enabled on Apache
  • Nginx has no try_files rule passing requests to index.php
  • WordPress installed in a subdirectory with a wrong RewriteBase
  • A plugin or custom post type registered rewrites without flushing them

How to fix it

  1. Re-save permalinks. Go to Settings > Permalinks and click Save Changes without changing anything. This flushes WordPress's rewrite rules and rewrites .htaccess if it is writable.
  2. Check .htaccess exists. In the WordPress root (enable hidden files), confirm .htaccess contains the '# BEGIN WordPress' block. If not, add it manually.
  3. Enable AllowOverride on your own Apache server. In the vhost's <Directory> block set AllowOverride All (or at least FileInfo), then reload Apache. Shared hosts already allow this.
  4. Enable mod_rewrite. On Debian/Ubuntu run sudo a2enmod rewrite and sudo systemctl reload apache2.
  5. Add try_files on Nginx. Nginx ignores .htaccess. In the site's location / block use try_files $uri $uri/ /index.php?$args; then run nginx -t and reload.
  6. Fix subdirectory installs. If WordPress lives in /blog/, set RewriteBase /blog/ and RewriteRule . /blog/index.php [L] in that folder's .htaccess.

.htaccess (WordPress root, Apache/LiteSpeed)

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

How to stop it happening again

  • Include .htaccess (a hidden file) in migrations and backups
  • Flush permalinks after activating plugins that add custom post types
  • Keep your Nginx WordPress config in version control

Frequently asked questions

Why does ?p=123 work but /my-post/ does not?

Query-string URLs go straight to index.php and need no rewriting. Pretty URLs depend on the server rewriting them, which is what is failing.

Does the 404 page look like the theme or plain?

A plain server 'Not Found' page means the request never reached WordPress (server rewrite issue). A themed 404 means WordPress ran but could not match the URL, so flush permalinks or check slugs.

I use LiteSpeed. Does .htaccess apply?

Yes. LiteSpeed reads Apache-style .htaccess rewrite rules, though after edits it may cache them briefly; restarting or waiting a moment applies changes.