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
- 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.
- 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.
- Enable mod_rewrite. On Debian/Ubuntu run sudo a2enmod rewrite and restart Apache. Verify with apachectl -M | grep rewrite.
- 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.
- 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.
- 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