Fix Apache Invalid command 'RewriteEngine', perhaps misspelled
Invalid command 'RewriteEngine' means mod_rewrite is not loaded. On Ubuntu run a2enmod rewrite and restart; elsewhere uncomment LoadModule rewrite_module.
AH00526: Syntax error on line 553 of /usr/local/apache2/conf/httpd.conf:Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configurationRewriteEngine belongs to mod_rewrite. When that module is not loaded, Apache does not know the word at all. It is not a typo — it is a missing module. On Ubuntu or Debian run sudo a2enmod rewrite and restart; with the official httpd image or a source build, uncomment LoadModule rewrite_module in httpd.conf.
[1] Check where the error came from. The same text shows up in two places with different symptoms.
| Where | Symptom | Prefix |
|---|---|---|
apachectl configtest, start or restart | Apache does not start | AH00526: Syntax error on line N of <file>: |
| error log, at request time | only requests in that directory get 500 | [core:alert] ... <path>/.htaccess: Invalid command 'RewriteEngine' |
.htaccess is read per request, so a config test never sees it. Step [5] covers that case.
[2] Check whether the module is loaded.
$ apachectl -M | grep rewrite rewrite_module (shared)No output means the module is off. If the config already has a syntax error, -M fails while reading it too: on Ubuntu apache2ctl -M printed nothing and exited 1. In that case follow the line number in the error message. On Ubuntu apache2ctl and apachectl do the same thing.
[3] On Ubuntu or Debian, enable it with a2enmod. It links mods-available/rewrite.load into mods-enabled/.
$ sudo a2enmod rewrite$ sudo apache2ctl configtestEnabling module rewrite.To activate the new configuration, you need to run: service apache2 restartSyntax OKAs a2enmod says, loading a new module needs a restart: sudo systemctl restart apache2. Connections drop briefly during the restart, so pick a quiet moment. To undo, run sudo a2dismod rewrite and restart again — but remove the RewriteEngine lines first, or Apache will fail to start with the same error.
[4] With the official httpd image or a source build, uncomment the line in httpd.conf. In the 2.4.69 official image it is line 199.
LoadModule rewrite_module modules/mod_rewrite.soIf there is no commented #LoadModule rewrite_module modules/mod_rewrite.so line at all, the module may not be built. Check the file first with ls /usr/local/apache2/modules/mod_rewrite.so. Rocky and RHEL httpd packages load modules from conf.modules.d/; that was not tested here.
[5] If the error comes from .htaccess, the config test passes. Here a directory has AllowOverride All, an .htaccess with RewriteEngine On, and the module is off:
$ curl -sI http://127.0.0.1/oldHTTP/1.1 500 Internal Server Error[Mon Oct 26 21:31:02.681817 2026] [core:alert] [pid 8:tid 12] [client 203.0.113.10:55292] /usr/local/apache2/htdocs/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configurationThe official .htaccess how-to also says to check the error log on a 500, where the line starts with the .htaccess path as above. The fix is the same as [3] or [4]; after loading the module the same request returned 301.
$ curl -sI http://127.0.0.1/oldHTTP/1.1 301 Moved PermanentlyLocation: http://127.0.0.1/new[6] Rules wrapped in <IfModule mod_rewrite.c> are silently skipped. Many apps ship their .htaccess this way. With the module off and the rules wrapped, the result was Syntax OK, no log line, and a 404 where a redirect was expected.
$ curl -sI http://127.0.0.1/oldHTTP/1.1 404 Not FoundThe official docs say everything inside a false <IfModule> test is ignored, and that the section should only be used when one config must work with or without the module. If redirects or pretty URLs do nothing and there is no error, check the module with [2].
If the rules now loop into a 500 see AH00124 internal redirect limit; for 403 see AH01630 Require all granted.
Analyze your Apache log in the browser ↗ — nothing is uploaded.