Ffile2fix
Sign in Get started

Fix .htaccess rewrite rules returning 404 Not Found

Not Found
The requested URL was not found on this server.

When clean URLs like /about return Apache's 404 while index.php?page=about works, your rewrite rules are not being applied. Usually Apache is ignoring .htaccess because AllowOverride is None, mod_rewrite is off, or the rules use the wrong RewriteBase for a subfolder install.

Also appears as: The requested URL /about was not found on this server. · AH00128: File does not exist: /var/www/html/about · AH01264: script not found or unable to stat · WordPress pretty permalinks 404 but ?p=123 works

Common causes

  • AllowOverride None in the site's Directory block, so Apache never reads .htaccess
  • mod_rewrite is not enabled, and the rules are wrapped in <IfModule mod_rewrite.c> so they silently do nothing
  • The site lives in a subfolder but RewriteBase or the fallback path still points to /
  • The .htaccess file is missing, misnamed (htaccess.txt) or was not uploaded because it is hidden
  • The server runs Nginx or LiteSpeed with a config that does not honour .htaccess
  • An earlier rule with the [L] flag or a conflicting RewriteCond stops processing before the front-controller rule

How to fix it

  1. Check that .htaccess is read at all. Put a deliberate garbage line at the top of .htaccess. If the site does not throw a 500 error, Apache is ignoring the file, so AllowOverride is the problem.
  2. Set AllowOverride. In the vhost or apache2.conf, set AllowOverride All (or at least FileInfo) in the <Directory> block for the document root, then run sudo apachectl configtest and reload Apache.
  3. Enable mod_rewrite. On Debian/Ubuntu run sudo a2enmod rewrite and restart Apache. Verify with apachectl -M | grep rewrite.
  4. Fix the base for subfolder installs. If the app is at /blog/, use RewriteBase /blog/ and rewrite to /blog/index.php, not /index.php. In WordPress, resaving Settings > Permalinks regenerates the correct rules.
  5. Test the rules in isolation. Reduce .htaccess to the standard front-controller block and test again, then add other rules back one at a time to find a conflict.
  6. Translate rules for Nginx. Nginx ignores .htaccess entirely. Use try_files $uri $uri/ /index.php?$args; in the location / block instead.

.htaccess (front controller)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

How to stop it happening again

  • Include AllowOverride and a2enmod rewrite in your server provisioning
  • Keep .htaccess under version control so it is deployed with the code
  • Update RewriteBase whenever you move the site to or from a subfolder
  • Validate rules before uploading changes to production

Frequently asked questions

Why does the homepage work but every other page 404?

The homepage is served directly by index.php without a rewrite. Every other clean URL needs the rewrite rule, so when rules are ignored only those pages fail.

Is AllowOverride All a security risk?

It lets .htaccess change more settings and costs a little performance. If you control the server, putting the rules directly in the vhost with AllowOverride None is faster and stricter.

Why do I get the application's own 404 instead of Apache's?

Then the rewrite works and the app received the request but has no matching route. Check the router or, in WordPress, flush permalinks.