Last Updated on 2026/06/30 by Tomylove
워드프레스에서 필수적으로 쓰이는 .htaccess 의 문법에서 정규식 문법 기초 중 특수 문자(sign)의 의미를 명확히 공부하며, 기록합니다.
복습하고 써보는 것이 최선인 것 같습니다.
htaccess mod_rewrite 기초 / rewrite rule 정규식 문법

텍스트 Text:
. 문자 하나 ( Any single character) : 앞에 점(‘.’) 표시가 있습니다. 식별이 잘 안될 수도 있기에 부연 설명.
[chars] 문자열 집합 “chars”중의 어느 한 문자, (Character class) : (Any character of the class “chars”)
[^chars] 문자열 집합 chars의 어느 한 문자를 포함 하지 않음, (Character class): (Not a character of the class “chars”)
text1|text2 text1 또는(or) text2 Alternative : text1 또는(or) text2
수량사 (Quantifiers), 수량사 = all, both처럼 양을 나타내는 한정사(determiner)나 대명사
? 0개 이상의 한 문자 (선행 문자가 0 또는 한번 발생(0 or 1 occurrences of the preceding text))
* 0개 이상의 다수 문자 (선행 문자 0번 또는 N번 발생 [ 0 or N occurrences of the preceding text ] (N > 0))
+ 1개 이상의 다수 문자 { 1 or N occurrences of the preceding text (N > 1) }
그룹 (Grouping) :
(text) 텍스트 그룹, 괄호로 묶음 (Grouping of text)
괄호로 묶은 문자열 그룹들은 Rewrite룰에서 후단에 $N과 같이 참조된다. 예를 들면 첫번째 문자열 그룹은 $1, 두번째 문자열 그룹은 $2.
(used either to set the borders of an alternative as above, or to make backreferences, where the Nth group can be referred to on the RHS of a RewriteRule as $N)
앵커(Anchors):
^ 줄의 시작을 선언(표시), Start-of-line anchor
$ 줄의 끝을 선언(표시), End-of-line anchor
회피(Escaping), 정규식에서 예약된 문자로부터 벗어남을 의미:
\char escape the given char
(역 슬래쉬 예를 들면, “.[]()”등이 한 문자, 문자열 집합, 문자열 그룹을 위해 예약된 기호이므로 단순한 텍스트로 인식하기 위해 정규식을 회피한다는 의미임)
for instance, to specify the chars “.[]()” etc.)
Reference : http://httpd.apache.org/docs/2.0/ko/mod/mod_rewrite.html
! 는 어떤 의미인가요? 제 .htaccess 파일엔 ! 부호도 있던데…
부정의 의미로 쓰입니다.
조건문 등에서 ‘~가 아닐 경우’의 의미로 ! 표시를 씁니다.