GrepBoard/매뉴얼
605 편 ·

Invalid command 'RewriteEngine' 오류 해결

·시험 환경 Apache 2.4.69 (Docker httpd:2.4) · Ubuntu 24.04 apache2 2.4.58 · 2026-10·시험 범위 ↓·6 단계

Invalid command 'RewriteEngine' 은 mod_rewrite 가 안 켜졌다는 뜻입니다. Ubuntu 는 a2enmod rewrite 후 재시작, 그 밖은 LoadModule 주석을 풉니다.

output
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 configuration

RewriteEngine 은 mod_rewrite 모듈의 지시어인데 그 모듈이 읽히지 않아서 Apache 가 낱말 자체를 모른다는 뜻입니다. 철자 문제가 아니라 모듈 문제입니다. Ubuntu·Debian 은 sudo a2enmod rewrite 후 재시작, 공식 httpd 이미지나 직접 빌드한 Apache 는 httpd.conf 의 LoadModule rewrite_module 주석을 풀면 됩니다.

[1] 오류가 어디서 났는지 봅니다. 같은 문구가 두 곳에서 나오고, 증상이 다릅니다.

나온 곳증상앞부분
apachectl configtest · 시작·재시작Apache 가 뜨지 않음AH00526: Syntax error on line N of <파일>:
오류 로그(요청 때)그 디렉터리의 요청만 500[core:alert] ... <경로>/.htaccess: Invalid command 'RewriteEngine'

.htaccess 쪽은 요청이 들어올 때 읽히므로 설정 검사로는 잡히지 않습니다. [5]에서 다룹니다.

[2] 모듈이 읽혔는지 확인합니다.

console
$ apachectl -M | grep rewrite
output
 rewrite_module (shared)

아무것도 안 나오면 모듈이 꺼져 있습니다. 단, 설정에 문법 오류가 있으면 -M 도 설정을 읽다가 실패하므로 Ubuntu 에서는 apache2ctl -M 이 출력 없이 종료 코드 1 로 끝났습니다. 그때는 오류 메시지의 줄 번호를 따릅니다. Ubuntu 에서는 apachectl 대신 apache2ctl 이라고 써도 같습니다.

[3] Ubuntu·Debian 은 a2enmod 로 켭니다. mods-available/rewrite.load 를 mods-enabled/ 로 잇는 명령입니다.

console
$ sudo a2enmod rewrite$ sudo apache2ctl configtest
output
Enabling module rewrite.To activate the new configuration, you need to run:  service apache2 restartSyntax OK

a2enmod 의 안내대로 모듈을 새로 읽힐 때는 재시작합니다: sudo systemctl restart apache2. 재시작하는 동안 연결이 잠깐 끊기므로 사람이 적은 때에 합니다. 되돌리려면 sudo a2dismod rewrite 후 같은 재시작입니다(그 전에 RewriteEngine 을 쓰는 설정을 먼저 빼지 않으면 같은 오류로 시작하지 못합니다).

[4] 공식 httpd 이미지·직접 빌드한 Apache 는 httpd.conf 에서 주석을 풉니다. 2.4.69 공식 이미지에서는 199행이었습니다.

/usr/local/apache2/conf/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so

주석을 풀기 전 #LoadModule rewrite_module modules/mod_rewrite.so 줄이 없으면 모듈 파일이 빌드에 들어 있지 않은 것입니다. ls /usr/local/apache2/modules/mod_rewrite.so 로 파일부터 봅니다. Rocky·RHEL 의 httpd 패키지는 conf.modules.d/ 에서 기본으로 읽지만 이번에는 시험하지 않았습니다.

[5] .htaccess 에서 났다면 설정 검사는 통과합니다. AllowOverride All 인 디렉터리에 RewriteEngine On 이 든 .htaccess 를 두고 모듈을 끈 결과입니다.

console
$ curl -sI http://127.0.0.1/oldHTTP/1.1 500 Internal Server Error
output
[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 configuration

공식 .htaccess 안내서도 500 이 나면 오류 로그를 보라고 하고, 로그 줄은 위처럼 .htaccess 경로로 시작한다고 적습니다. 고치는 법은 [3]·[4]와 같고, 모듈을 켠 뒤 같은 요청이 301 로 바뀌었습니다.

console
$ curl -sI http://127.0.0.1/oldHTTP/1.1 301 Moved PermanentlyLocation: http://127.0.0.1/new

[6] <IfModule mod_rewrite.c> 로 감싼 규칙은 오류 없이 조용히 빠집니다. 많은 앱의 .htaccess 가 이렇게 감싸 둡니다. 모듈이 꺼진 채로 감싼 규칙을 넣으니 Syntax OK 에 로그도 없이, 넘겨야 할 주소가 404 였습니다.

console
$ curl -sI http://127.0.0.1/oldHTTP/1.1 404 Not Found

공식 문서도 <IfModule> 의 조건이 거짓이면 그 사이를 통째로 무시한다고 하고, 모듈 유무와 상관없이 돌아가야 하는 설정에서만 쓰라고 합니다. 리다이렉트·예쁜 주소가 안 먹는데 오류가 없다면 [2]로 모듈부터 봅니다.

규칙이 켜진 뒤 무한 반복으로 500 이 나면 AH00124 internal redirect limit, 403 이면 AH01630 Require all granted를 봅니다.

Apache 로그를 브라우저에서 바로 분석 ↗ — 아무것도 올라가지 않습니다.

#apache#mod_rewrite#a2enmod#htaccess