Common causes
- mod_rewrite is installed but not enabled, which is the default on fresh Debian/Ubuntu Apache installs
- On RHEL/Alma/Rocky the LoadModule rewrite_module line is commented out in conf.modules.d
- The same issue with other modules: Header needs mod_headers, ExpiresActive needs mod_expires
- php_value or php_flag in .htaccess while PHP runs as PHP-FPM/CGI instead of mod_php
- A typo or invisible character (BOM, smart quotes) at the start of the line
- The server is not Apache (for example Nginx proxying to a minimal Apache) and lacks the module
How to fix it
- Confirm which directive failed. Read the Apache error log (/var/log/apache2/error.log or /var/log/httpd/error_log). The message names the exact directive and the file and line.
- Enable mod_rewrite on Debian/Ubuntu. Run sudo a2enmod rewrite, then sudo apachectl configtest and sudo systemctl restart apache2.
- Enable it on RHEL-based systems. Check that LoadModule rewrite_module modules/mod_rewrite.so is present and uncommented in /etc/httpd/conf.modules.d/00-base.conf, then restart httpd.
- Enable other missing modules the same way. For Header run a2enmod headers; for ExpiresActive run a2enmod expires. Verify with apachectl -M | grep -E 'rewrite|headers|expires'.
- Replace php_value under PHP-FPM. When PHP runs via FPM, php_value is invalid in .htaccess. Move those settings to .user.ini in the site root or to the FPM pool config.
- Ask your host on shared hosting. Shared cPanel hosts nearly always load mod_rewrite. If you see this there, check for typos and hidden characters, or contact support.
Shell + .htaccess
# Debian / Ubuntu
sudo a2enmod rewrite headers
sudo apachectl configtest && sudo systemctl restart apache2
apachectl -M | grep -E 'rewrite|headers'
# .htaccess: guard rules so a missing module does not cause a 500
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule> How to stop it happening again
- Include a2enmod rewrite headers in your server provisioning script
- Wrap optional rules in <IfModule> blocks in distributable .htaccess files
- Run apachectl configtest before every restart