Invalid command 'RewriteEngine' high
Apache 500: Invalid command 'RewriteEngine' (mod_rewrite)
Apache hit a RewriteEngine directive while mod_rewrite was not loaded or .htaccess overrides were forbidden, so it aborted with a 500.
What you see
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
What’s actually happening
The whole site (or one app) throws 500 Internal Server Error, and the error_log shows "Invalid command 'RewriteEngine'". WordPress permalinks, Laravel, and most PHP frameworks break instantly because their .htaccess starts with RewriteEngine On. If the directive is in the main config rather than .htaccess, Apache won't even start — `apachectl configtest` fails.
Common causes
- mod_rewrite isn't enabled, so Apache doesn't recognize any Rewrite* directive.
- AllowOverride is None for that directory, so the .htaccess containing RewriteEngine is parsed but its directives are treated as invalid in that context.
- Fresh server build or container image where only the base Apache modules are installed.
- The directive sits inside a <Directory> or vhost context where the rewrite module's directives aren't permitted because the module load failed silently earlier in the config.
- Typo or wrong module — copying config between distros where the module name differs.
How to fix it
- Enable mod_rewriteOn Debian/Ubuntu: `a2enmod rewrite && systemctl restart apache2`. On RHEL/CentOS, make sure /etc/httpd/conf.modules.d/ has `LoadModule rewrite_module modules/mod_rewrite.so` and restart with `systemctl restart httpd`. This alone fixes most cases.
- Allow .htaccess overridesModule loaded but still failing? The directory's AllowOverride is probably None. In the vhost set:\n<Directory /var/www/html>\n AllowOverride All\n</Directory>\nReload Apache. Without this, .htaccess rules are ignored or rejected even with mod_rewrite present.
- Verify the module actually loadedRun `apachectl -M | grep rewrite`. If `rewrite_module` isn't listed, the LoadModule line is missing, commented, or pointing at a path that doesn't exist. Fix the load line, then re-check before touching anything else.
- Validate config before reloading`apachectl configtest` (or `httpd -t`) tells you exactly which file and line Apache chokes on. If RewriteEngine is in httpd.conf/vhost rather than .htaccess, the server is down until you either load the module or remove the directive.
- In containers, bake the module inFor the official php:apache or httpd images, add `RUN a2enmod rewrite` to the Dockerfile and rebuild. A running container won't survive a restart with the change made by hand.
Stop it recurring
Add `apachectl -M | grep rewrite` and `apachectl configtest` to your deploy script so a missing module fails the deploy instead of the live site.
Related errors