서 버
설정 지시자
RewriteCond TestString CondPattern [flags]
RewriteCond는 룰의 상태를 정의하며 RewriteRule 지시자전에 하나이상의 RewriteCond가 올수 있습니다.
먼저 나온룰이 매치될 경우 다음룰이 작용됩니다.
1. TestString
다음과 같은 내용이 올수 있습니다.
1) RewriteRule backreferences(RewriteRule 후방참조) -> form $N (0 <= N <= 9)
|
RewriteEngine on RewriteCond /mirror/of/remotesite/$1 -U RewriteRule ^http://www\.remotesite\.com/(.*)$ /mirror/of/remotesite/$1 |
위 예에서 $1은 아래 RewriteRule의 (.*)를 참조합니다.
2) RewriteCond backreferences(RewriteRule 후방참조) -> form %N (1 <= N <= 9)
|
## ## vhost.map ## www.vhost1.dom:80 /path/to/docroot/vhost1 www.vhost2.dom:80 /path/to/docroot/vhost2 : www.vhostN.dom:80 /path/to/docroot/vhostN ## ## httpd.conf ## : # use the canonical hostname on redirects, etc. UseCanonicalName on : # add the virtual host in front of the CLF-format CustomLog /path/to/access_log "%{VHOST}e %h %l %u %t \"%r\" %>s %b" : # enable the rewriting engine in the main server RewriteEngine on # define two maps: one for fixing the URL and one which defines # the available virtual hosts with their corresponding # DocumentRoot. RewriteMap lowercase int:tolower RewriteMap vhost txt:/path/to/vhost.map
# Now do the actual virtual host mapping # via a huge and complicated single rule: # # 1. make sure we don't map for common locations RewriteCond %{REQUEST_URI} !^/commonurl1/.* RewriteCond %{REQUEST_URI} !^/commonurl2/.* : RewriteCond %{REQUEST_URI} !^/commonurlN/.* # # 2. make sure we have a Host header, because # currently our approach only supports # virtual hosting through this header RewriteCond %{HTTP_HOST} !^$ # # 3. lowercase the hostname RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$ # # 4. lookup this hostname in vhost.map and # remember it only when it is a path # (and not "NONE" from above) RewriteCond ${vhost:%1} ^(/.*)$ # # 5. finally we can map the URL to its docroot location # and remember the virtual host for logging purposes RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}] : |
위 예제는 RewriteCond ${vhost:%1} ^(/.*)$ 에서 %1은 바로위 RewriteCond의 (.+)를 참조합니다.
3) RewriteMap expansions(RewriteMap 확장) -> form ${mapname:key|default}
위 예제에서 RewriteCond ${vhost:%1} ^(/.*)$
4) Server-Variables(시스템 변수) -> form %{ NAME_OF_VARIABLE }
|
HTTP headers: HTTP_USER_AGENT connection & request: REMOTE_ADDR server internals: DOCUMENT_ROOT date and time: TIME_YEAR specials: API_VERSION |
위 예제에서 RewriteCond %{HTTP_HOST} !^$
2. CondPattern
펄 호환 정규표현식입니다. 정규표현식외 아래 것들이 올수 있습니다.
|
-'<CondPattern' (lexicographically precedes) -'>CondPattern' (lexicographically follows) -'=CondPattern' (lexicographically equal) -'-d' (is directory) -'-f' (is regular file) -'-s' (is regular file, with size) -'-l' (is symbolic link) -'-x' (has executable permissions) -'-F' (is existing file, via subrequest) -'-U' (is existing URL, via subrequest) |
아래 예는 보시면 %{REQUEST_FILENAME}이 크기가 있는 정규파일이 아니라면의 의미가 됩니다.
|
RewriteCond %{REQUEST_FILENAME} !-s RewriteRule ^page\.html$ page.cgi [T=application/x-httpd-cgi,L] |
3. flags
CondPattern뒤 세번째 아규먼트로 [flags]가 올수 있습니다.
|
- 'nocase|NC'(no case) - 'ornext|OR'(or next condition) - 'novary|NV'(no vary) -> HTTP header가 상태에 사용될 경우, 응답 vary 헤더에 해당 헤러가 들어가지 않도록 합니다. |
아래 예에서 사용법을 보실수 있습니다.
|
RewriteEngine on RewriteMap hosts-deny txt:/path/to/hosts.deny RewriteCond ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND [OR] RewriteCond ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND RewriteRule ^/.* - [F] |

좋은 팁 감사합니다!