서 버
설정지시자
RewriteRule Pattern Substitution [flags]
Server 설정, Virtual host 설정, Directory 설정, .htaccess 에 올수 있고,
하나 이상이 올경우 순서가 중요합니다.
1. Pattern
처음나오는 RewriteRule은 요청의 URL-path에 적용되고
다음패턴은 최근매치된 RewriteRule의 출력물에 적용이 됩니다.
* URL-path는 hostname, port 다음, query string전에 나오는 것을 말합니다.
%{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING}에 적용을 원하시면 RewriteCond를 이용하실수 있습니다.
2. Substitution
1) file-system path
2) URL-path
* 참고로 여기서 file-system path인지 URL-path인지의 구분은 path의 첫번째 segment가 루트 파일시스템
에 존재한다면 file-system path로 취급됩니다.
[PT] flag를 통해 URL-path에 적용되도록 할수도 있습니다.
3) Absolute URL
* 우선 hostname을 현재 호스트와 매치여부를 확인후 매치한다면 스키마와 호스트네임값은 버린 결과 경로
를 URL-path로 취급합니다.
매치하지 않는 다면 외부 리다이렉트를 수행합니다. 물론 [R] flag 사용을 통해 외부 리다이렉트를 강제할
수 있습니다.
4) -(dash) 대체가 필요없고 flag 적용이 필요할때 사용합니다.
3. [flags]
- 'B'(excape backreferences)
query string에 특수문자가 올때 사용할 필요가 있을지도 모릅니다.
- 'chain|C'(chained with next rule)
사용의 주용도는 앞쪽룰에 매치하지 않을 경우 다음룰은 skip 된다는데 있습니다.
- 'cookie|CO=NAME:VAL:domain[:lifetime[:path[:secure[:httponly]]]]' (set cookie)
- 'discardpathinfo|DPI'(discard PATH_INFO)
- 'env|E=VAR:VAL' (set environment variable)
- 'forbidden|F' (force URL to be forbidden)
- 'gone|G' (force URL to be gone)
- 'last|L' (last rule)
- 'next|N' (next round)
rewriting process를 다시 시작할때 사용된다.
- 'nocase|NC' (no case)
- 'noescape|NE' (no URI escaping of output)
rewrite의 결과에 URL escaping rules에 적용되지 않도록 한다.
- 'nosubreq|NS' (not for internal sub-requests)
- 'proxy|P' (force proxy)
- 'passthrough|PT' (pass through to next handler)
- 'qsappend|QSA' (query string append)
- 'redirect|R [=code]' (force redirect)
- 'skip|S=num' (skip next rule(s))
- 'type|T=MIME-type' (force MIME type)

좋은 정보 감사합니다.