<-
Apache > HTTP Server > Documentation > Version 2.2 > Miscellaneous Documentation

URL ÀçÀÛ¼º Áöħ¼­

°¡´ÉÇÑ ¾ð¾î:  en  |  ko 

ÀÌ ¹®¼­´Â ÃÖ½ÅÆÇ ¹ø¿ªÀÌ ¾Æ´Õ´Ï´Ù. ÃÖ±Ù¿¡ º¯°æµÈ ³»¿ëÀº ¿µ¾î ¹®¼­¸¦ Âü°íÇϼ¼¿ä.

¿øÀúÀÚ
Ralf S. Engelschall <[email protected]>
1997³â 12¿ù

ÀÌ ¹®¼­´Â mod_rewrite ÂüÁ¶ ¹®¼­¸¦ º¸ÃæÇÑ´Ù. ÀÌ ¹®¼­´Â À¥°ü¸®ÀÚ°¡ ½ÇÁ¦ ÀÛ¾÷¿¡¼­ ºÎµúÄ¡°ÔµÇ´Â ÀüÇüÀûÀÎ URL°ü·Ã ¹®Á¦¸¦ ÇØ°áÇϱâÀ§Çؼ­ ¾î¶»°Ô ¾ÆÆÄÄ¡ mod_rewrite¸¦ »ç¿ëÇÏ´ÂÁö ¼³¸íÇÑ´Ù. URL ÀçÀÛ¼º ±ÔÄ¢À» ¼³Á¤ÇÏ¿© ¹®Á¦¸¦ ÇØ°áÇÏ´Â ¹æ¹ýÀ» ÀÚ¼¼È÷ ¼³¸íÇÑ´Ù.

top

mod_rewrite ¼Ò°³

¾ÆÆÄÄ¡ mod_rewrite ¸ðµâÀº ±²ÀåÇÏ´Ù. Áï, URLÀ» Á¶ÀÛÇÒ ¼ö ÀÖ´Â °­·ÂÇÏ°í ½Ç·Î Á¤±³ÇÑ ¸ðµâÀÌ´Ù. »ó»óÇØ¿Ô´ø °ÅÀÇ ¸ðµç Á¾·ùÀÇ URL Á¶ÀÛÀÌ °¡´ÉÇÏ´Ù. ±×·¯³ª ±× ´ë°¡·Î »ç¿ëÇϱ⠺¹ÀâÇÏ´Ù. mod_rewriteÀÇ ÃÖ´ë ´ÜÁ¡Àº Ãʺ¸ÀÚ°¡ ÀÌÇØÇÏ°í »ç¿ëÇϱ⠽±Áö ¾Ê´Ù´Â Á¡ÀÌ´Ù. ½ÉÁö¾î ¾ÆÆÄÄ¡ Àü¹®°¡µµ Á¾Á¾ mod_rewriteÀÇ »õ·Î¿î ¿ëµµ¸¦ ¹ß°ßÇÑ´Ù.

´Ù¸¥ ¸»·Î: mod_rewrite¿¡ ´ëÇØ ´ç½ÅÀº óÀ½¿¡ °ÌÀ» ¸Ô°í Àý´ë·Î ´Ù½Ã »ç¿ëÇÏÁö ¾Ê°Å³ª, °­·ÂÇÔ¿¡ ¸Å·áµÇ¾î ¾ÕÀ¸·Î »î µ¿¾È »ç¶û¿¡ ºüÁú °ÍÀÌ´Ù. ÀÌ ±ÛÀº ù¹ø° °æ¿ì¸¦ ¸·±âÀ§ÇØ ÀÌ¹Ì ¾Ë·ÁÁø ¸î°¡Áö ¼º°ø»ç·Ê¸¦ ¼Ò°³ÇÏ·Á°í ÇÑ´Ù.

top

½Ç¿ëÀûÀÎ ÇØ°áÃ¥

ÀÌÁ¦ ³»°¡ Á÷Á¢ ¸¸µé¾ú°Å³ª ´Ù¸¥ »ç¶÷µéÀÌ ¸¸µç ¸¹Àº ½Ç¿ëÀûÀÎ ÇØ°áÃ¥ÀÌ ³ª¿Â´Ù. ¿¹Á¦¿¡¼­ URL ÀçÀÛ¼ºÀÇ È渶¼úÀ» ¸¶À½²¯ ¹è¿ì±æ ¹Ù¶õ´Ù.

ÁÖÀÇ: ¼­¹ö ¼³Á¤¿¡ µû¶ó »óȲ¿¡ ¸Â°Ô ¿¹Á¦¸¦ Á¶±Ý ¼öÁ¤ÇØ¾ß ÇÒ °æ¿ì°¡ ÀÖ´Ù. ¿¹¸¦ µé¾î, Ãß°¡·Î mod_alias, mod_userdir µîÀ» »ç¿ëÇÑ´Ù¸é [PT] Ç÷¡±×¸¦ Ãß°¡ÇÑ´Ù. ȤÀº ÁÖ¼­¹ö¼³Á¤/°¡»óÈ£½ºÆ® »ç¿ëÀå¼Ò°¡ ¾Æ´Ñ .htaccess »ç¿ëÀå¼Ò¿¡ ¾Ë¸Â°Ô ±ÔÄ¢À» ¼öÁ¤ÇÒ ¼öµµ ÀÖ´Ù. »ç¿ëÇϱâ Àü¿¡ Ç×»ó ±ÔÄ¢ÀÌ ¾î¶² ±â´ÉÀ» ÇÏ´ÂÁö ÀÌÇØÇϵµ·Ï Çضó. ±×·¯¸é ¹®Á¦¸¦ ÇÇÇÒ ¼ö ÀÖ´Ù.
top

URL ±¸Á¶

±âÁØÀÌ µÇ´Â URL

»óȲ¼³¸í:

ÇÑ ¸®¼Ò½º¿¡ ´ëÇØ ¿©·¯ URLÀ» °¡Áö´Â À¥¼­¹ö°¡ ÀÖ´Ù. º¸Åë (½ÇÁ¦ »ç¿ëÇÏ°í ¾Ë·ÁÁ®¾ß ÇÒ) ±âÁØÀÌ µÇ´Â URL°ú, ´ÜÃà ȤÀº ³»ºÎ ¿ëµµÀÇ URLÀÌ ÀÖ´Ù. »ç¿ëÀÚ°¡ ¿äû¿¡ ¾î¶² URLÀ» »ç¿ëÇÏ´øÁö ±âÁØÀÌ µÇ´Â URL¸¸À» º¸¿©Áà¾ß ÇÑ´Ù.

ÇØ°áÃ¥:

±âÁØÀÌ µÇÁö¾Ê´Â ¸ðµç URLÀ» ºê¶ó¿ìÀú°¡ ¾Ëµµ·Ï °íÄ¡±âÀ§ÇØ ¿ÜºÎ HTTP ¸®´ÙÀÌ·º¼ÇÇÑ´Ù. ¿¹¸¦ µé¾î ¾Æ·¡ ±ÔÄ¢Àº /~user¸¦ ±âÁØÀÌ µÇ´Â /u/user·Î ´ëüÇÏ°í, /u/user ¸¶Áö¸·¿¡ ½½·¡½¬°¡ ¾ø´Ù¸é Ãß°¡ÇÑ´Ù.

RewriteRule   ^/~([^/]+)/?(.*)    /u/$1/$2  [R]
RewriteRule   ^/([uge])/([^/]+)$  /$1/$2/   [R]

±âÁØÀÌ µÇ´Â È£½ºÆ®¸í

»óȲ¼³¸í:
...
ÇØ°áÃ¥:
RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R]
RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://fully.qualified.domain.name/$1 [L,R]

DocumentRoot¸¦ ¿Å±ä °æ¿ì

»óȲ¼³¸í:

À¥¼­¹öÀÇ DocumentRoot´Â º¸Åë URL "/"°ú Á÷Á¢ °ü·ÃÀÖ´Ù. ±×·¯³ª ÀÌ°÷¿¡ ¸ðµç ÀÚ·á°¡ ÀÖÁö ¾Ê°í, ÀÚ·á°¡ ´Ù¸¥ ¿©·¯ °÷¿¡ Èð¾îÁ®ÀÖ´Â °æ¿ì°¡ ÀÖ´Ù. ¿¹¸¦ µé¾î ÀÎÆ®¶ó³Ý »çÀÌÆ®¿¡ (¿ÜºÎ¸¦ À§ÇÑ È¨ÆäÀÌÁö) /e/www/¿Í (ÀÎÆ®¶ó³ÝÀ» À§ÇÑ È¨ÆäÀÌÁö) /e/sww/°¡ ÀÖ´Ù°í ÇÏÀÚ. ÀÌÁ¦ DocumentRoot°¡ /e/www/À̱⶧¹®¿¡, ¿äû¿¡¼­ ÆäÀÌÁö¿¡ Æ÷ÇÔµÈ ±×¸² µîÀ» ÀÌ°÷¿¡¼­ °¡Á®¿Í¾ß ÇÑ´Ù.

ÇØ°áÃ¥:

¿ì¸®´Â URL /¸¦ /e/www/·Î ¸®´ÙÀÌ·º¼Ç¸¸ ÇÏ¸é µÈ´Ù. »ç¼ÒÇØ º¸ÀÌÁö¸¸ ½ÇÁ¦·Î mod_rewrite¸¦ »ç¿ëÇؼ­¸¸ °¡´ÉÇÏ´Ù. (mod_alias µîÀÌ Á¦°øÇÏ´Â) URL Alias °°Àº ÀüÇüÀûÀÎ ¹æ¹ýÀº ¾ÕºÎºÐ¸¸ ã´Â´Ù. DocumentRoot°¡ ¸ðµç URLÀÇ ¾ÕºÎºÐÀ̱⶧¹®¿¡ ÀÌ ¹æ¹ýÀ» »ç¿ëÇÏ¿© ¸®´ÙÀÌ·º¼ÇÀ» ÇÒ ¼ö ¾ø´Ù. mod_rewrite¸¦ »ç¿ëÇϸé ÁøÂ¥ °£´ÜÇÏ´Ù:

RewriteEngine on
RewriteRule   ^/$  /e/www/  [R]

¸¶Áö¸· ½½·¡½¬ ¹®Á¦

»óȲ¼³¸í:

µð·ºÅ丮¸¦ ÁöĪÇÏ´Â URLÀÇ ¸¶Áö¸· ½½·¡½¬ ¹®Á¦°¡ ¾ø´Ù¸é ¸ðµç À¥°ü¸®Àڴ ȯȣÇÒ °ÍÀÌ´Ù. ½½·¡½¬°¡ ¾ø´Ù¸é, Áï /~quux/foo/ ´ë½Å /~quux/foo¸¦ »ç¿ëÇÏ¸é ¼­¹ö°¡ foo¶ó´Â ÆÄÀÏÀ» ã±â¶§¹®¿¡ ¿À·ù°¡ ¹ß»ýÇÑ´Ù. ÆÄÀÏÀÌ µð·ºÅ丮À̱⶧¹®¿¡ ¹Þ¾ÆµéÀÌÁö ¾Ê´Â´Ù. ´ëºÎºÐÀÇ °æ¿ì º¸Åë ¼­¹ö°¡ ÀÚµ¿À¸·Î URLÀ» °íÄ¡Áö¸¸, °¡²û Á÷Á¢ ÇØÁà¾ß ÇÒ °æ¿ì°¡ ÀÖ´Ù. ¿¹¸¦ µé¾î, CGI ½ºÅ©¸³Æ® µîÀ¸·Î º¹ÀâÇÑ URL ÀçÀÛ¼ºÀ» ÇÑ ÈÄ¿¡ ±×·¯ÇÏ´Ù.

ÇØ°áÃ¥:

ÀÌ ¹Ì¹¦ÇÑ ¹®Á¦ÀÇ ÇØ°á¹æ¹ýÀº ¼­¹ö°¡ ÀÚµ¿À¸·Î ¸¶Áö¸· ½½·¡½¬¸¦ Ãß°¡ÇÏ´Â °ÍÀÌ´Ù. ºê¶ó¿ìÀú°¡ ³ª¸ÓÁö ±×¸² µîÀ» ¿Ã¹Ù·Î ¿äûÇÒ ¼ö ÀÖµµ·Ï, ¿ÜºÎ ¸®´ÙÀÌ·º¼ÇÀ» ÇØ¾ß ÇÑ´Ù. ³»ºÎ ¸®´ÙÀÌ·º¼ÇÀ» ÇÑ´Ù¸é µð·ºÅ丮 ÆäÀÌÁö¿¡¸¸ µ¿ÀÛÇÏ¿© ÀÌ ÆäÀÌÁö°¡ »ó´ë URL·Î Æ÷ÇÔÇÏ´Â ±×¸²À» ºê¶ó¿ìÀú°¡ ¿äûÇÒ¶§ ãÀ» ¼ö ¾ø´Ù. ¿¹¸¦ µé¾î, ¿ÜºÎ ¸®´ÙÀÌ·º¼ÇÀ» »ç¿ëÇÏÁö ¾ÊÀ»¶§ /~quux/foo/index.html¿¡¼­ image.gif¸¦ ¿äûÇϸé /~quux/image.gif¸¦ ¿äûÇÏ°Ô µÈ´Ù!

±×·¡¼­ À̸¦ ÇØ°áÇϱâÀ§ÇØ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÑ´Ù:

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo$  foo/  [R]

Ȩµð·ºÅ丮ÀÇ ÃÖ»óÀ§ .htaccess ÆÄÀÏ¿¡ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÒ ¼öµµ ÀÖ´Ù. ±×·¯³ª ó¸®Çϴµ¥ ºÎ´ãÀÌ µÈ´Ù.

RewriteEngine  on
RewriteBase    /~quux/
RewriteCond    %{REQUEST_FILENAME}  -d
RewriteRule    ^(.+[^/])$           $1/  [R]

ÀÏ°üµÈ URL ±¸Á¶·Î ¸¸µç À¥Å¬·¯½ºÅÍ

»óȲ¼³¸í:

ÀÎÆ®¶ó³Ý À¥¼­¹ö±ºÀÇ ¸ðµç À¥¼­¹ö¿¡ µ¿ÀÏÇÏ°í ÀÏ°üµÈ URL ±¸Á¶¸¦ ¸¸µé°í ½Í´Ù. Áï, ¸ðµç (Á¤ÀÇ»ó ¼­¹ö¿¡ ¼ÓÇÏ¿© ¼­¹ö¿¡ ÀÇÁ¸ÀûÀÎ!) URLÀ» ¼­¹ö µ¶¸³ÀûÀ¸·Î ¸¸µç´Ù! À¥ À̸§°ø°£¿¡ ¼­¹öµ¶¸³ÀûÀÎ µ¿ÀÏÇÑ ±¸Á¶¸¦ ºÎ¿©ÇØ¾ß ÇÑ´Ù: URLÀº ½ÇÁ¦ ¼­¹ö¸¦ ÁöĪÇÏ¸é ¾ÈµÈ´Ù. ¼­¹ö±ºÀÌ ÀÚµ¿À¸·Î ½ÇÁ¦ ¼­¹ö·Î À¯µµÇÑ´Ù.

ÇØ°áÃ¥:

¸ÕÀú »ç¿ëÀÚ, ±×·ì, µ¶¸³Ã¼ÀÇ À§Ä¡ Á¤º¸¸¦ ÀúÀåÇÑ (ºÐ»êµÈ) ¿ÜºÎ¸Ê¿¡ ½ÇÁ¦ ¼­¹ö Á¤º¸¸¦ ¾ò¾î¿Â´Ù. ¿ÜºÎ¸ÊÀº ´ÙÀ½°ú °°Àº Çü½ÄÀÌ´Ù

user1  server_of_user1
user2  server_of_user2
:      :

¿ì¸®´Â ÀÌ Á¤º¸¸¦ °¢°¢ map.xxx-to-host ÆÄÀÏ¿¡ ÀúÀåÇß´Ù. ´ÙÀ½À¸·Î ¸ðµç ¼­¹ö¿¡¼­ URLÀÌ ¼­¹ö¿¡ ¾ø´Ù¸é ´ÙÀ½°ú °°Àº URLÀ»,

/u/user/anypath
/g/group/anypath
/e/entity/anypath

´ÙÀ½°ú °°ÀÌ ¸®´ÙÀÌ·º¼ÇÇÑ´Ù

http://physical-host/u/user/anypath
http://physical-host/g/group/anypath
http://physical-host/e/entity/anypath

¾Æ·¡ ±ÔÄ¢Àº ¸ÊÆÄÀÏÀ» »ç¿ëÇÏ¿© ÀÌ ÀÛ¾÷À» ÇÑ´Ù (server0Àº ¸Ê¿¡ Ç׸ñÀÌ ¾ø´Â °æ¿ì »ç¿ëÇÒ ±âº»¼­¹ö¶ó°í °¡Á¤ÇÑ´Ù):

RewriteEngine on

RewriteMap      user-to-host   txt:/path/to/map.user-to-host
RewriteMap     group-to-host   txt:/path/to/map.group-to-host
RewriteMap    entity-to-host   txt:/path/to/map.entity-to-host

RewriteRule   ^/u/([^/]+)/?(.*)   http://${user-to-host:$1|server0}/u/$1/$2
RewriteRule   ^/g/([^/]+)/?(.*)  http://${group-to-host:$1|server0}/g/$1/$2
RewriteRule   ^/e/([^/]+)/?(.*) http://${entity-to-host:$1|server0}/e/$1/$2

RewriteRule   ^/([uge])/([^/]+)/?$          /$1/$2/.www/
RewriteRule   ^/([uge])/([^/]+)/([^.]+.+)   /$1/$2/.www/$3\

Ȩµð·ºÅ丮¸¦ ´Ù¸¥ À¥¼­¹ö·Î ÀÌÀü

»óȲ¼³¸í:

¸¹Àº À¥°ü¸®ÀÚ´Â À¥¼­¹öÀÇ ¸ðµç Ȩµð·ºÅ丮¸¦ ´Ù¸¥ À¥¼­¹ö·Î ÀÌÀüÇÑ °æ¿ì ÇØ°áÃ¥À» ¹°¾îº»´Ù. ÀÌ ¹æ¹ýÀº ÀÌÀü ¼­¹ö¸¦ ´ëüÇÒ »õ·Î¿î ¼­¹ö¸¦ ±¸¼ºÇϴµ¥ ½Ã°£ÀÌ °É¸®´Â °æ¿ì¿¡ ÇÊ¿äÇÏ´Ù.

ÇØ°áÃ¥:

mod_rewrite¸¦ »ç¿ëÇÏ¸é °£´ÜÇÏ´Ù. ÀÌÀü À¥¼­¹ö´Â ¸ðµç /~user/anypath URLÀ» http://newserver/~user/anypath·Î ¸®´ÙÀÌ·º¼ÇÇÏ¸é µÈ´Ù.

RewriteEngine on
RewriteRule   ^/~(.+)  http://newserver/~$1  [R,L]

Ȩµð·ºÅ丮 ±¸Á¶ ¸¸µé±â

»óȲ¼³¸í:

»ç¿ëÀÚ°¡ ¼öõ¸íÀÎ »çÀÌÆ®´Â º¸Åë Ȩµð·ºÅ丮 ±¸Á¶¸¦ ¸¸µç´Ù. Áï, ¿¹¸¦ µé¾î À̸§ÀÌ »ç¿ëÀÚ¸íÀÇ Ã¹¹ø° ¹®ÀÚÀÎ ÇÏÀ§µð·ºÅ丮¿¡ Ȩµð·ºÅ丮¸¦ µÐ´Ù. ±×·¡¼­, /~foo/anypath´Â /home/f/foo/.www/anypathÀÌ°í, /~bar/anypath´Â /home/b/bar/.www/anypathÀÌ´Ù.

ÇØ°áÃ¥:

¹°°áÇ¥½Ã°¡ ÀÖ´Â URLÀ» À§¿Í °°Àº ±¸Á¶·Î º¯È¯ÇϱâÀ§ÇØ ´ÙÀ½ ±ÔÄ¢À» »ç¿ëÇÑ´Ù.

RewriteEngine on
RewriteRule   ^/~(([a-z])[a-z0-9]+)(.*)  /home/$2/$1/.www$3

ÆÄÀϽýºÅÛ À籸¼º

»óȲ¼³¸í:

ÀÌ ¿¹´Â ½Ç·Î ÇϵåÄÚ¾îÀûÀÌ´Ù: µð·ºÅ丮º° RewriteRules¸¦ ¸Å¿ì ¸¹ÀÌ »ç¿ëÇÏ¿© ÀÚ·á ÀÚü´Â ±×´ë·Î µÐü·Î À¥¿¡ ÀڷḦ ÀÚ¿¬½º·´°Ô ºê¶ó¿ì¡Çϵµ·Ï ÇÑ´Ù. ¹è°æ: ³ª´Â 1992³â ºÎÅÍ ÀÚÀ¯·Ó°Ô »ç¿ëÇÒ ¼ö ÀÖ´Â À¯´Ð½º ¼ÒÇÁÆ®¿þ¾îµéÀ» net.sw¿¡ ¸ð¾ÆµÎ°í ÀÖ¾ú´Ù. ÀÌ´Â ³»°¡ ÄÄÇ»ÅÍ°úÇÐÀ» °øºÎÇϸ鼭 ¿©·¯Çص¿¾È ¿©°¡½Ã°£¿¡ ½Ã½ºÅÛ °ü¸®ÀÚ¿Í ³×Æ®¿÷ °ü¸®ÀÚ¸¦ ÇؿԱ⶧¹®¿¡ ³» Ãë¹ÌÀÌÀÚ ÀÏÀÌ´Ù. ¸ÅÁÖ¸¶´Ù »õ·Î ¼ÒÇÁÆ®¿þ¾î°¡ Ãß°¡µÉ ¶§¸¶´Ù µð·ºÅ丮¸¦ ±í°Ô ¸¸µé¾î¿Ô´Ù:

drwxrwxr-x   2 netsw  users    512 Aug  3 18:39 Audio/
drwxrwxr-x   2 netsw  users    512 Jul  9 14:37 Benchmark/
drwxrwxr-x  12 netsw  users    512 Jul  9 00:34 Crypto/
drwxrwxr-x   5 netsw  users    512 Jul  9 00:41 Database/
drwxrwxr-x   4 netsw  users    512 Jul 30 19:25 Dicts/
drwxrwxr-x  10 netsw  users    512 Jul  9 01:54 Graphic/
drwxrwxr-x   5 netsw  users    512 Jul  9 01:58 Hackers/
drwxrwxr-x   8 netsw  users    512 Jul  9 03:19 InfoSys/
drwxrwxr-x   3 netsw  users    512 Jul  9 03:21 Math/
drwxrwxr-x   3 netsw  users    512 Jul  9 03:24 Misc/
drwxrwxr-x   9 netsw  users    512 Aug  1 16:33 Network/
drwxrwxr-x   2 netsw  users    512 Jul  9 05:53 Office/
drwxrwxr-x   7 netsw  users    512 Jul  9 09:24 SoftEng/
drwxrwxr-x   7 netsw  users    512 Jul  9 12:17 System/
drwxrwxr-x  12 netsw  users    512 Aug  3 20:15 Typesetting/
drwxrwxr-x  10 netsw  users    512 Jul  9 14:08 X11/

1996³â 7¿ù ÀÌ ÀúÀå¼Ò¸¦ ¸ÚÀÖ´Â À¥ ÀÎÅÍÆäÀ̽º¸¦ ÅëÇØ ¼¼»ó¿¡ °ø°³Çϱâ·Î °áÁ¤ÇÞ´Ù. "¸ÚÀÖ´Ù"´Â ¸»Àº, ÃÖ»óÀ§ µð·ºÅ丮¿¡ CGI ½ºÅ©¸³Æ®¸¦ µÎÁö ¾Ê°íµµ, ÀúÀå¼Ò °èÃþ±¸Á¶¸¦ Á÷Á¢ ºê¶ó¿ìÁúÇÏ±æ ¹Ù¶õ´Ù´Â ¶æÀÌ´Ù. ¿Ö? ÀúÀå¼Ò¸¦ ³ªÁß¿¡ FTP·Îµµ Á¢±ÙÇÒ ¼ö ÀÖµµ·Ï ¸¸µé ¿¹Á¤ÀÌ¿´±â¶§¹®¿¡ À¥À̳ª CGI¿Í °ü·ÃµÈ ³»¿ëÀ» °°ÀÌ µÎ±â ½È¾ú´Ù.

ÇØ°áÃ¥:

ÇØ°áÃ¥Àº µÎ ºÎºÐÀ¸·Î ³ª´¶´Ù: ¸ÕÀú µð·ºÅ丮 ¼öÁØ¿¡¼­ ÇÊ¿äÇÑ ¸ðµç ÆäÀÌÁö¸¦ µ¿ÀûÀ¸·Î ¸¸µå´Â CGI ½ºÅ©¸³Æ®°¡ ÇÊ¿äÇÏ´Ù. ³ª´Â ÀÌ ½ºÅ©¸³Æ®µéÀ» ´ÙÀ½°ú °°ÀÌ /e/netsw/.www/¿¡ µÎ¾ú´Ù:

-rw-r--r--   1 netsw  users    1318 Aug  1 18:10 .wwwacl
drwxr-xr-x  18 netsw  users     512 Aug  5 15:51 DATA/
-rw-rw-rw-   1 netsw  users  372982 Aug  5 16:35 LOGFILE
-rw-r--r--   1 netsw  users     659 Aug  4 09:27 TODO
-rw-r--r--   1 netsw  users    5697 Aug  1 18:01 netsw-about.html
-rwxr-xr-x   1 netsw  users     579 Aug  2 10:33 netsw-access.pl
-rwxr-xr-x   1 netsw  users    1532 Aug  1 17:35 netsw-changes.cgi
-rwxr-xr-x   1 netsw  users    2866 Aug  5 14:49 netsw-home.cgi
drwxr-xr-x   2 netsw  users     512 Jul  8 23:47 netsw-img/
-rwxr-xr-x   1 netsw  users   24050 Aug  5 15:49 netsw-lsdir.cgi
-rwxr-xr-x   1 netsw  users    1589 Aug  3 18:43 netsw-search.cgi
-rwxr-xr-x   1 netsw  users    1885 Aug  1 17:41 netsw-tree.cgi
-rw-r--r--   1 netsw  users     234 Jul 30 16:35 netsw-unlimit.lst

DATA/ ÇÏÀ§µð·ºÅ丮¿¡ À§¿¡¼­ ¸»ÇÑ ÀúÀå¼Ò°¡ ÀÖ´Ù. ½ÇÁ¦ net.swÀÇ ³»¿ëÀº º¸Åë rdist¸¦ »ç¿ëÇÏ¿© ÀÚµ¿À¸·Î °¡Á®¿Â´Ù. µÎ¹ø° ºÎºÐÀÌ ³²¾Ò´Ù: ¾î¶»°Ô ÀÌ µÎ ±¸Á¶¸¦ ÇϳªÀÇ ÀÚ¿¬½º·¯¿î URL ±¸Á¶·Î ¿¬°áÇϴ°¡? »ç¿ëÀÚ¿¡°Ô DATA/ µð·ºÅ丮¸¦ °¨Ãß°í, URL¸¶´Ù ÀûÀýÇÑ CGI ½ºÅ©¸³Æ®¸¦ ½ÇÇàÇÏ°í ½Í´Ù. ÇØ°áÃ¥Àº ´ÙÀ½°ú °°´Ù: ¸ÕÀú ¼­¹öÀÇ DocumentRoot¿¡¼­ °ø°³µÈ URL /net.sw/¸¦ ³»ºÎ °æ·Î /e/netsw·Î ÀçÀÛ¼ºÇϱâÀ§ÇØ µð·ºÅ丮º° ¼³Á¤ÆÄÀÏ¿¡ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÑ´Ù:

RewriteRule  ^net.sw$       net.sw/        [R]
RewriteRule  ^net.sw/(.*)$  e/netsw/$1

ù¹ø° ±ÔÄ¢Àº ¸¶Áö¸·¿¡ ½½·¡½¬°¡ ¾ø´Â ¿äûÀ» À§Çؼ­ »ç¿ëÇß´Ù! µÎ¹ø° ±ÔÄ¢ÀÌ ½ÇÁ¦ ÀÛ¾÷À» ÇÑ´Ù. ±×¸®°í µð·ºÅ丮º° ¼³Á¤ÆÄÀÏ /e/netsw/.www/.wwwacl¿¡ °áÁ¤ÀûÀÎ ¼³Á¤ÀÌ ³ª¿Â´Ù:

Options       ExecCGI FollowSymLinks Includes MultiViews

RewriteEngine on

#  ¾Õ ºÎºÐÀÌ /net.sw/ ·Î Á¢±ÙÇÑ´Ù
RewriteBase   /net.sw/

#  ¸ÕÀú ÃÖ»óÀ§ µð·ºÅ丮¸¦
#  cgi ½ºÅ©¸³Æ®·Î ÀçÀÛ¼ºÇÑ´Ù
RewriteRule   ^$                       netsw-home.cgi     [L]
RewriteRule   ^index\.html$            netsw-home.cgi     [L]

#  ºê¶ó¿ìÀú°¡ µð·ºÅ丮º° ÆäÀÌÁö¸¦ ¿äûÇÑ °æ¿ì
#  ÇÏÀ§µð·ºÅ丮¸¦ ÃßÃâÇÑ´Ù
RewriteRule   ^.+/(netsw-[^/]+/.+)$    $1                 [L]

#  ÀÌÁ¦ ÀçÀÛ¼ºÀ» ¸¶Ä£´Ù
RewriteRule   ^netsw-home\.cgi.*       -                  [L]
RewriteRule   ^netsw-changes\.cgi.*    -                  [L]
RewriteRule   ^netsw-search\.cgi.*     -                  [L]
RewriteRule   ^netsw-tree\.cgi$        -                  [L]
RewriteRule   ^netsw-about\.html$      -                  [L]
RewriteRule   ^netsw-img/.*$           -                  [L]

#  ´Ù¸¥ cgi ½ºÅ©¸³Æ®°¡ ó¸®ÇÒ
#  ÇÏÀ§µð·ºÅ丮°¡ ³²¾Ò´Ù
RewriteRule   !^netsw-lsdir\.cgi.*     -                  [C]
RewriteRule   (.*)                     netsw-lsdir.cgi/$1

Çؼ®À» À§ÇÑ ÈùÆ®:

  1. ³×¹ø° ºÎºÐ¿¡¼­ ´ëü Çʵå('-')°¡ ¾ø°í L (last) Ç÷¡±×°¡ ÀÖÀ½À» ÁÖ¸ñÇ϶ó
  2. ¸¶Áö¸· ºÎºÐ¿¡¼­ ù¹ø° ±ÔÄ¢¿¡ ! (not) ¹®ÀÚ¿Í C (chain) Ç÷¡±×¸¦ ÁÖ¸ñÇ϶ó
  3. ¸¶Áö¸· ±ÔÄ¢¿¡¼­ ±âŸ ÇØ´çÇÏÁö ¾Ê´Â ¸ðµç °æ¿ì¸¦ Àâ¾Æ³»´Â ÆÐÅÏÀ» ÁÖ¸ñÇ϶ó

NCSA imagemapÀ» ¾ÆÆÄÄ¡ mod_imagemapÀ¸·Î

»óȲ¼³¸í:

»ç¶÷µéÀº NCSA À¥¼­¹ö¿¡¼­ Çö´ëÀûÀÎ ¾ÆÆÄÄ¡ À¥¼­¹ö·Î ÀÚ¿¬½º·´°Ô ¿Å°Ü°¡±æ ¹Ù¶õ´Ù. ±×·¡¼­ ¿À·¡µÈ NCSA imagemap ÇÁ·Î±×·¥À» »ç¿ëÇÑ ÆäÀÌÁö¸¦ Çö´ëÀûÀÎ ¾ÆÆÄÄ¡ mod_imagemap·Î ó¸®ÇÏ±æ ¹Ù¶õ´Ù. ¹®Á¦´Â imagemap ÇÁ·Î±×·¥À» /cgi-bin/imagemap/path/to/page.map°ú °°ÀÌ ÂüÁ¶ÇÏ´Â ÇÏÀÌÆÛ¸µÅ©°¡ ¸¹´Ù´Â °ÍÀÌ´Ù. ¾ÆÆÄÄ¡´Â /path/to/page.map°ú °°Àº ¿äûÀ» ¹Þ¾Æ¾ß ÇÑ´Ù.

ÇØ°áÃ¥:

¸ðµç ¿äû¿¡¼­ ¾ÕºÎºÐÀ» µ¿ÀûÀ¸·Î Á¦°ÅÇÏ´Â Àü¿ª ±ÔÄ¢À» »ç¿ëÇÑ´Ù:

RewriteEngine  on
RewriteRule    ^/cgi-bin/imagemap(.*)  $1  [PT]

¿©·¯ µð·ºÅ丮¿¡¼­ ÆäÀÌÁö °Ë»ö

»óȲ¼³¸í:

°¡²û À¥¼­¹ö°¡ ¿©·¯ µð·ºÅ丮¿¡¼­ ÆÄÀÏÀ» ã¾Æ¾ß ÇÒ ¶§°¡ ÀÖ´Ù. ÀÌ °æ¿ì MultiViews³ª ´Ù¸¥ ¹æ¹ýÀº µµ¿òÀÌ ¾ÈµÈ´Ù.

ÇØ°áÃ¥:

¿©·¯ µð·ºÅ丮¿¡¼­ ÆÄÀÏÀ» ã´Â ±ÔÄ¢À» Á÷Á¢ ÇÁ·Î±×·¥ÇÑ´Ù.

RewriteEngine on

#   ¸ÕÀú custom/¿¡¼­ ã±æ ½ÃµµÇÏ°í...
#   ...ãÀ¸¸é ³¡!
RewriteCond         /your/docroot/dir1/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.+)  /your/docroot/dir1/$1  [L]

#   µÎ¹ø°·Î pub/¿¡¼­ ã±æ ½ÃµµÇÑ´Ù...
#   ...ãÀ¸¸é ³¡!
RewriteCond         /your/docroot/dir2/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.+)  /your/docroot/dir2/$1  [L]

#   ¸øãÀ¸¸é ´Ù¸¥ Alias³ª ScriptAlias Áö½Ã¾î µîÀ¸·Î ÁøÇàÇÑ´Ù.
RewriteRule   ^(.+)  -  [PT]

URL¿¡ µû¶ó ȯ°æº¯¼ö¸¦ ¼³Á¤ÇÑ´Ù

»óȲ¼³¸í:

¿äûµé°£¿¡ »óÅÂÁ¤º¸¸¦ À¯ÁöÇϱâÀ§ÇØ URL¿¡ Á¤º¸¸¦ ÀÎÄÚµùÇÏ´Â ¹æ¹ýµµ ÀÖ´Ù. ±×·¯³ª ´ÜÁö ÀÌ Á¤º¸¸¦ Á¦°ÅÇϱâÀ§ÇØ ¸ðµç ÆäÀÌÁö¿¡ CGI wrapper¸¦ »ç¿ëÇÏ°í ½ÍÁö ¾Ê´Ù.

ÇØ°áÃ¥:

ÀçÀÛ¼º ±ÔÄ¢À» »ç¿ëÇÏ¿© »óÅÂÁ¤º¸¸¦ ÃßÃâÇÏ°í, ÃßÃâÇÑ Á¤º¸¸¦ ³ªÁß¿¡ XSSI³ª CGI¿¡¼­ »ç¿ëÇϱâÀ§ÇØ È¯°æº¯¼ö¿¡ ÀúÀåÇÑ´Ù. ±×·¡¼­ URL /foo/S=java/bar/´Â /foo/bar/·Î º¯È¯µÇ°í STATUS¶ó´Â ȯ°æº¯¼ö °ªÀ» "java"·Î ¼³Á¤ÇÑ´Ù.

RewriteEngine on
RewriteRule   ^(.*)/S=([^/]+)/(.*)    $1/$3 [E=STATUS:$2]

°¡»ó »ç¿ëÀÚ È£½ºÆ®

»óȲ¼³¸í:

°¡»óÈ£½ºÆ®¸¦ »ç¿ëÇÏÁö ¾Ê°í °°Àº ÄÄÇ»ÅÍ·Î DNS A ·¹Äڵ带 ¼³Á¤ÇÏ¿© www.username.host.domain.comÀ» »ç¿ëÀÚÀÇ È¨ÆäÀÌÁö·Î Á¦°øÇÏ°í ½Í´Ù.

ÇØ°áÃ¥:

HTTP/1.0 ¿äûÀÇ °æ¿ì ¹æ¹ýÀÌ ¾øÁö¸¸, Host: HTTP Çì´õ¸¦ Æ÷ÇÔÇÑ HTTP/1.1 ¿äûÀº ´ÙÀ½ ±ÔÄ¢À» »ç¿ëÇÏ¿© ³»ºÎÀûÀ¸·Î http://www.username.host.com/anypath¸¦ /home/username/anypath·Î ÀçÀÛ¼ºÇÒ ¼ö ÀÖ´Ù:

RewriteEngine on
RewriteCond   %{HTTP_HOST}                 ^www\.[^.]+\.host\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^www\.([^.]+)\.host\.com(.*) /home/$1$2

Ȩµð·ºÅ丮¸¦ ¿ÜºÎ ¼­¹ö·Î ¸®´ÙÀÌ·º¼Ç

»óȲ¼³¸í:

Áö¿ª µµ¸ÞÀÎ ourdomain.com ¹Û¿¡¼­ ¿äûÀÌ µé¾î¿À¸é Ȩµð·ºÅ丮 URLÀ» ´Ù¸¥ À¥¼­¹ö www.somewhere.comÀ¸·Î ¸®´Ù¸®·º¼ÇÇÏ±æ ¹Ù¶õ´Ù. Á¾Á¾ °¡»óÈ£½ºÆ® »ç¿ëÀå¼Ò¿¡¼­ »ç¿ëÇÑ´Ù.

ÇØ°áÃ¥:

ÀçÀÛ¼º Á¶°ÇÀ» »ç¿ëÇÏ¸é µÈ´Ù:

RewriteEngine on
RewriteCond   %{REMOTE_HOST}  !^.+\.ourdomain\.com$
RewriteRule   ^(/~.+)         http://www.somewhere.com/$1 [R,L]

½ÇÆÐÇÑ URLÀ» ´Ù¸¥ À¥¼­¹ö·Î ¸®´ÙÀÌ·º¼Ç

»óȲ¼³¸í:

URL ÀçÀÛ¼º¿¡ ´ëÇؼ­ À¥¼­¹ö A¿¡ ÇØ´ç ÆÄÀÏÀÌ ¾ø´Â °æ¿ì À¥¼­¹ö B·Î ¿äûÀ» ¸®´ÙÀÌ·º¼ÇÇÏ´Â ¹æ¹ýÀ» ÀÚÁÖ ¹°¾îº»´Ù. º¸Åë Perl·Î ÀÛ¼ºÇÑ ErrorDocument CGI ½ºÅ©¸³Æ®¸¦ »ç¿ëÇÏÁö¸¸, mod_rewrite¸¦ »ç¿ëÇÏ´Â ¹æ¹ýµµ ÀÖ´Ù. ±×·¯³ª ¼º´ÉÀº ErrorDocument CGI ½ºÅ©¸³Æ®º¸´Ù ¶³¾îÁüÀ» ¸í½ÉÇ϶ó!

ÇØ°áÃ¥:

ù¹ø° ¹æ¹ýÀº ºü¸£Áö¸¸ À¯¿¬¼ºÀÌ ¶³¾îÁö°í ¿ÏÀüÇÏÁö ¾Ê´Ù:

RewriteEngine on
RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
RewriteRule   ^(.+)                             http://webserverB.dom/$1

ÀÌ ¹æ¹ýÀÇ ´ÜÁ¡Àº DocumentRoot ¾È¿¡ ÀÖ´Â ÆäÀÌÁö¸¸ °¡´ÉÇÏ´Ù´Â Á¡ÀÌ´Ù. (¿¹¸¦ µé¾î Ȩµð·ºÅ丮 µîÀ» À§ÇØ) Á¶°ÇÀ» Ãß°¡ÇÒ ¼ö ÀÖÁö¸¸, ´õ ÁÁÀº ¹æ¹ýÀÌ ÀÖ´Ù:

RewriteEngine on
RewriteCond   %{REQUEST_URI} !-U
RewriteRule   ^(.+)          http://webserverB.dom/$1

mod_rewriteÀÇ URL Àü¹æÂüÁ¶(look-ahead)¸¦ »ç¿ëÇÑ´Ù. ±×·¡¼­ ¸ðµç URL¿¡ µ¿ÀÛÇÏ°í ¾ÈÀüÇÏ´Ù. ±×·¯³ª ¸ðµç ¿äû¸¶´Ù ³»ºÎ ÇÏÀ§¿äûÀ» Çѹø ´õ Çϱ⶧¹®¿¡ À¥¼­¹ö ¼º´É¿¡ ¾Ç¿µÇâÀ» ÁØ´Ù. ±×·¡¼­ °­·ÂÇÑ CPU¿¡¼­ À¥¼­¹ö¸¦ ½ÇÇàÇÑ´Ù¸é »ç¿ëÇ϶ó. ÄÄÇ»ÅÍ°¡ ´À¸®´Ù¸é ù¹ø° ¹æ¹ýÀ̳ª ´õ ³ªÀº ErrorDocument CGI ½ºÅ©¸³Æ®¸¦ »ç¿ëÇ϶ó.

È®Àå ¸®´ÙÀÌ·º¼Ç

»óȲ¼³¸í:

°¡²û ¸®´ÙÀÌ·º¼ÇÇÏ´Â URLÀ» ´õ Á¶ÀýÇÒ ÇÊ¿ä°¡ ÀÖ´Ù. ¾ÆÆÄÄ¡ ³»ºÎ URL escape ÇÔ¼ö´Â "url#anchor" °°Àº URLÀÇ anchorµµ escapeÇÑ´Ù. ¾ÆÆÄÄ¡ÀÇ uri_escape() ÇÔ¼ö´Â ¿ì¹°Á¤ÀÚ(#)µµ °°ÀÌ escapeÇϹǷΠ»ç¿ëÇÒ ¼ö ¾ø´Ù. ±×·¯¸é ¾î¶»°Ô ÀÌ·± URL·Î ¸®´ÙÀÌ·º¼ÇÇÒ ¼ö ÀÖ³ª?

ÇØ°áÃ¥:

Á÷Á¢ ¸®´ÙÀÌ·º¼ÇÇÏ´Â NPH-CGI ½ºÅ©¸³Æ®¸¦ »ç¿ëÇÑ ÇØ°áÃ¥ÀÌ ÇÊ¿äÇÏ´Ù. escape¸¦ ÇÏÁö ¾Ê±â¶§¹®ÀÌ´Ù (NPH=non-parseable headers). ¸ÕÀú ´ÙÀ½ ¼­¹ö¼³Á¤À» ÇÏ¿© (ÀçÀÛ¼º ±ÔÄ¢ÀÇ ³¡ºÎºÐ¿¡ »ç¿ëÇØ¾ß ÇÑ´Ù) »õ·Î¿î URL scheme xredirect:¸¦ µµÀÔÇÑ´Ù:

RewriteRule ^xredirect:(.+) /path/to/nph-xredirect.cgi/$1 \
            [T=application/x-httpd-cgi,L]

±×·¯¸é xredirect:·Î ½ÃÀÛÇÏ´Â ¸ðµç URLÀº nph-xredirect.cgi ÇÁ·Î±×·¥À» ÅëÇÏ°Ô µÈ´Ù. ÇÁ·Î±×·¥Àº ´ÙÀ½°ú °°´Ù:

#!/path/to/perl
##
##  nph-xredirect.cgi -- NPH/CGI script for extended redirects
##  Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
##

$| = 1;
$url = $ENV{'PATH_INFO'};

print "HTTP/1.0 302 Moved Temporarily\n";
print "Server: $ENV{'SERVER_SOFTWARE'}\n";
print "Location: $url\n";
print "Content-type: text/html\n";
print "\n";
print "<html>\n";
print "<head>\n";
print "<title>302 Moved Temporarily (EXTENDED)</title>\n";
print "</head>\n";
print "<body>\n";
print "<h1>Moved Temporarily (EXTENDED)</h1>\n";
print "The document has moved <a HREF=\"$url\">here</a>.<p>\n";
print "</body>\n";
print "</html>\n";

##EOF##

±×·¯¸é mod_rewrite°¡ Á÷Á¢ ¹ÞÁö¸øÇÏ´Â ¸ðµç URL schemeÀ¸·Î ¸®´ÙÀÌ·º¼ÇÇÒ ¼ö ÀÖ´Ù. ¿¹¸¦ µé¾î, ´ÙÀ½°ú °°ÀÌ news:newsgroupÀ¸·Î ¸®´ÙÀÌ·º¼ÇÇÒ ¼ö ÀÖ´Ù

RewriteRule ^anyurl  xredirect:news:newsgroup
ÁÖÀÇ: À§ÀÇ Æ¯º°ÇÑ "Åë°ú" ±ÔÄ¢À» »ç¿ëÇÏ¿© xredirect:¸¦ ¸¶Áö¸·¿¡ È®ÀåÇØ¾ß Çϱ⶧¹®¿¡ ±ÔÄ¢¿¡ [R]À̳ª [R,L]À» »ç¿ëÇÏ¸é ¾ÈµÈ´Ù.

ÀúÀå¼Ò Á¢±Ù Áß°è(multiplexer)

»óȲ¼³¸í:

http://www.perl.com/CPAN¿¡ ÀÖ´Â ´ë´ÜÇÑ CPAN (Comprehensive Perl Archive Network)À» ¾Æ´Â°¡? ÀÌ ÁÖ¼Ò´Â ¼¼°è¿¡ Èð¾îÁø ¿©·¯ CPAN ¹Ì·¯ FTP ¼­¹öÁß Å¬¶óÀ̾ðÆ®¿¡ °¡±îÀÌ ÀÖ´Â ¼­¹ö·Î ¸®´ÙÀÌ·º¼ÇÇÑ´Ù. À̸¦ FTP Á¢±Ù Áß°è ¼­ºñ½º¶ó°í ÇÑ´Ù. CPANÀº CGI ½ºÅ©¸³Æ®¸¦ »ç¿ëÇÏÁö¸¸, mod_rewrite¸¦ »ç¿ëÇÏ¿© ºñ½ÁÇÏ°Ô ¸¸µé ¼ö ÀÖÀ»±î?

ÇØ°áÃ¥:

¸ÕÀú mod_rewrite 3.0.0 ¹öÀüºÎÅÍ ¸®´ÙÀÌ·º¼Ç¿¡ "ftp:" schemeÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù. ´ÙÀ½À¸·Î Ŭ¶óÀ̾ðÆ®ÀÇ ÃÖ»óÀ§ µµ¸ÞÀÎÀ» RewriteMap°ú °°ÀÌ »ç¿ëÇÏ¿© À§Ä¡¸¦ ÃßÁ¤ÇÒ ¼ö ÀÖ´Ù. º¹ÀâÈ÷ ¿«ÀÎ ±ÔÄ¢¿¡¼­ ÃÖ»óÀ§ µµ¸ÞÀÎÀ» Áß°è¸ÊÀÇ Å°·Î »ç¿ëÇÑ´Ù.

RewriteEngine on
RewriteMap    multiplex                txt:/path/to/map.cxan
RewriteRule   ^/CxAN/(.*)              %{REMOTE_HOST}::$1                 [C]
RewriteRule   ^.+\.([a-zA-Z]+)::(.*)$  ${multiplex:$1|ftp.default.dom}$2  [R,L]
##
##  map.cxan -- Multiplexing Map for CxAN
##

de        ftp://ftp.cxan.de/CxAN/
uk        ftp://ftp.cxan.uk/CxAN/
com       ftp://ftp.cxan.com/CxAN/
 :
##EOF##

½Ã°£¿¡ µû¸¥ ÀçÀÛ¼º

»óȲ¼³¸í:

½Ã°£¿¡ µû¶ó ´Ù¸¥ ³»¿ëÀ» ¼­ºñ½ºÇÏ´Â °æ¿ì ¸¹Àº À¥°ü¸®ÀÚ´Â Àá½Ã Ưº°ÇÑ ÆäÀÌÁö·Î ¸®´ÙÀÌ·º¼ÇÇϱâÀ§ÇØ CGI ½ºÅ©¸³Æ®¸¦ »ç¿ëÇÑ´Ù. mod_rewrite·Î´Â ¾î¶»°Ô ÇÒ ¼ö Àִ°¡?

ÇØ°áÃ¥:

ÀçÀÛ¼º Á¶°Ç¿¡¼­ »ç¿ëÇÒ ¼ö ÀÖ´Â ¿©·¯ TIME_xxx º¯¼ö°¡ ÀÖ´Ù. º¯¼ö¿Í Ưº°ÇÑ »çÀü¼ø¼­ ºñ±³ <STRING, >STRING, =STRINGÀ» »ç¿ëÇÏ¿© ½Ã°£¿¡ µû¶ó ¸®´ÙÀÌ·º¼ÇÇÒ ¼ö ÀÖ´Ù:

RewriteEngine on
RewriteCond   %{TIME_HOUR}%{TIME_MIN} >0700
RewriteCond   %{TIME_HOUR}%{TIME_MIN} <1900
RewriteRule   ^foo\.html$             foo.day.html
RewriteRule   ^foo\.html$             foo.night.html

URL foo.htmlÀ» ¿äûÇϸé 07:00-19:00 µ¿¾È foo.day.html ³»¿ëÀ» ¼­ºñ½ºÇÏ°í, ³ª¸ÓÁö ½Ã°£ µ¿¾È foo.night.html ³»¿ëÀ» ¼­ºñ½ºÇÑ´Ù. ȨÆäÀÌÁö¿¡¼­ »ç¿ëÇϱâ ÁÁÀº ±â´ÉÀÌ´Ù...

YYYY¸¦ XXXX·Î ÀÌÀüÇÑ °æ¿ì ¿ªÈ£È¯

»óȲ¼³¸í:

¿©·¯ .html ÆÄÀÏÀ» .phtml·Î º¯È¯ÇÏ´Â µî document.YYYY¸¦ document.XXXX·Î ÀÌÀüÇÑÈÄ ¿ªÈ£È¯(backward compatibility) URLÀ» (°¡»óÀûÀ¸·Î Á¸ÀçÇÏ°Ô) ¸¸µé ¼ö ÀÖ³ª?

ÇØ°áÃ¥:

À̸§À» ±âº»À̸§À¸·Î ÀçÀÛ¼ºÇÑÈÄ »õ·Î¿î È®ÀåÀÚ¸¦ °¡Áø ÆÄÀÏÀÌ ÀÖ´ÂÁö °Ë»çÇÑ´Ù. ÀÖ´Ù¸é ±× ÆÄÀϸíÀ» »ç¿ëÇÏ°í, ¾øÀ¸¸é URLÀ» ¿ø·¡ »óÅ·ΠÀçÀÛ¼ºÇÑ´Ù.

#   ¹®¼­.html ÀÌ ¾ø°í
#   ¹®¼­.phtml ¸¸ ÀÖ´Â °æ¿ì
#   ¹®¼­.html À» ¹®¼­.phtml ·Î
#   ÀçÀÛ¼ºÇÏ´Â ¿ªÈ£È¯ ±ÔÄ¢
RewriteEngine on
RewriteBase   /~quux/
#   ±âº»À̸§À» ã°í, ã¾Ò´Ù´Â »ç½ÇÀ» ±â¾ïÇÑ´Ù
RewriteRule   ^(.*)\.html$              $1      [C,E=WasHTML:yes]
#   ÆÄÀÏÀÌ ÀÖ´Ù¸é ¹®¼­.phtml ·Î ÀçÀÛ¼ºÇÑ´Ù
RewriteCond   %{REQUEST_FILENAME}.phtml -f
RewriteRule   ^(.*)$ $1.phtml                   [S=1]
#   ¾Æ´Ï¸é ¾Õ¿¡¼­ ãÀº ±âº»À̸§À» µÇµ¹¸°´Ù
RewriteCond   %{ENV:WasHTML}            ^yes$
RewriteRule   ^(.*)$ $1.html
top

ÄÁÅÙÃ÷ ´Ù·ç±â

»õ·Î ÀÌÀü (°¨Ãß±â)

»óȲ¼³¸í:

ÃÖ±Ù foo.htmlÀ» bar.html·Î º¯°æÇÏ°í ¿ªÈ£È¯¼ºÀ» À§ÇØ ÀÌÀü URLÀ» °è¼Ó Á¦°øÇÏ°í ½Í´Ù°í °¡Á¤ÇÏÀÚ. »ç¿ëÀÚ´Â ÀÌÀü URLÀÌ º¯°æµÇ¾ú´Ù´Â »ç½ÇÀ» ´«Ä¡Ã¤Áö ¸øÇÑ´Ù.

ÇØ°áÃ¥:

´ÙÀ½ ±ÔÄ¢À¸·Î ÀÌÀü URLÀ» ³»ºÎÀûÀ¸·Î »õ·Î¿î URL·Î ÀçÀÛ¼ºÇÑ´Ù:

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo\.html$  bar.html

»õ·Î ÀÌÀü (¾Ë¸®±â)

»óȲ¼³¸í:

´Ù½Ã foo.htmlÀ» bar.html·Î º¯°æÇÏ°í ¿ªÈ£È¯¼ºÀ» À§ÇØ ÀÌÀü URLÀ» °è¼Ó Á¦°øÇÏ°í ½Í´Ù°í °¡Á¤ÇÏÀÚ. ±×·¯³ª ÀÌÁ¦´Â ÀÌÀü URLÀ» »ç¿ëÇÏ¸é »ç¿ëÀÚ¿¡°Ô »õ·Î¿î URLÀ» ÈùÆ®·Î ¾Ë·ÁÁØ´Ù. Áï, ºê¶ó¿ìÀú ÁÖ¼ÒâÀÌ º¯ÇÑ´Ù.

ÇØ°áÃ¥:

»õ·Î¿î URL·Î HTTP ¸®´ÙÀÌ·º¼ÇÇÏ´Ù. ±×·¯¸é ºê¶ó¿ìÀú°¡ »õ·Î¿î URL¸¦ º¸ÀÌ°í º¯°æ»ç½ÇÀ» »ç¿ëÀÚ°¡ ¾Ë°ÔµÈ´Ù:

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo\.html$  bar.html  [R]

ºê¶ó¿ìÀú¿¡ µû¸¥ ³»¿ë

»óȲ¼³¸í:

ÃÖ¼ÒÇÑ Áß¿äÇÑ ÃÖ»óÀ§ ÆäÀÌÁö´Â ºê¶ó¿ìÀú¿¡ ÃÖÀûÈ­µÈ ³»¿ëÀ¸·Î ¼­ºñ½ºÇؾßÇÒ °æ¿ì°¡ ÀÖ´Ù. Áï, ÃֽŠNetscape ºê¶ó¿ìÀú¿¡°Ô´Â ÃÖ»óÀÇ ¹öÀüÀ», Lynx ºê¶ó¿ìÀú¿¡°Ô´Â ÃÖÀú ¹öÀüÀ», ³ª¸ÓÁö ºê¶ó¿ìÀú¿¡´Â Æò±ÕÀûÀÎ ¹öÀüÀ» Á¦°øÇÑ´Ù.

ÇØ°áÃ¥:

ºê¶ó¿ìÀú°¡ ³»¿ëÇù»óÀ» À§ÇØ ÀÚ½ÅÀÇ Á¾·ù¿¡ ´ëÇÑ Á¤º¸¸¦ Á¦°øÇÏÁö ¾Ê±â¶§¹®¿¡ ³»¿ëÇù»óÀ» »ç¿ëÇÒ ¼ö ¾ø´Ù. ´ë½Å HTTP "User-Agent" Çì´õ¸¦ »ç¿ëÇÑ´Ù. ´ÙÀ½ ±ÔÄ¢Àº HTTP "User-Agent" Çì´õ°¡ "Mozilla/3"À¸·Î ½ÃÀÛÇϸé foo.html ÆäÀÌÁö¸¦ foo.NS.html·Î ÀçÀÛ¼ºÇÏ°í ÀçÀÛ¼ºÀ» Áß´ÜÇÑ´Ù. ºê¶ó¿ìÀú°¡ "Lynx"³ª "Mozilla" ¹öÀü 1 ȤÀº 2¶ó¸é URLÀº foo.20.htmlÀÌ µÈ´Ù. ³ª¸ÓÁö ºê¶ó¿ìÀú´Â foo.32.html ÆäÀÌÁö¸¦ ¹Þ´Â´Ù. ¾Æ·¡ ±ÔÄ¢ÀÌ ÀÌ ÀÛ¾÷À» ÇÑ´Ù:

RewriteCond %{HTTP_USER_AGENT}  ^Mozilla/3.*
RewriteRule ^foo\.html$         foo.NS.html          [L]

RewriteCond %{HTTP_USER_AGENT}  ^Lynx/.*         [OR]
RewriteCond %{HTTP_USER_AGENT}  ^Mozilla/[12].*
RewriteRule ^foo\.html$         foo.20.html          [L]

RewriteRule ^foo\.html$         foo.32.html          [L]

µ¿Àû ¹Ì·¯

»óȲ¼³¸í:

¿ÜºÎ È£½ºÆ®¿¡ ¿ì¸® »çÀÌÆ®·Î °¡Á®¿À°í ½ÍÀº ÁÁÀº À¥ÆäÀÌÁö°¡ ÀÖ´Ù°í °¡Á¤ÇÏÀÚ. FTP ¼­¹öÀÇ °æ¿ì Á÷Á¢ ¿ÜºÎ ÀÚ·áÀÇ Ãֽź¹»çº»À» À¯ÁöÇÏ´Â mirror ÇÁ·Î±×·¥À» »ç¿ëÇÒ ¼ö ÀÖ°í, À¥¼­¹ö¶ó¸é HTTP·Î ºñ½ÁÇÑ ÀÛ¾÷À» ÇÏ´Â webcopy ÇÁ·Î±×·¥À» »ç¿ëÇÒ ¼ö ÀÖ´Ù. ±×·¯³ª µÎ ¹æ¹ý ¸ðµÎ ´ÜÁ¡ÀÌ ÀÖ´Ù: º¹»çº»Àº °¡²û¾¿ ÇÁ·Î±×·¥À» ½ÇÇàÇØÁÙ ¶§¸¸ ÃÖ½ÅÆÇÀ¸·Î À¯ÁöµÈ´Ù. Á÷Á¢ ±¸¼ºÇؾßÇÏ´Â Á¤ÀûÀÎ ¹Ì·¯°¡ ¾Æ´Ï¶ó¸é ÁÁ°Ú´Ù. ´ë½Å (¿ÜºÎ È£½ºÆ®¿¡¼­ ÀÚ·á°¡ °»½ÅµÇ¸é) ÇÊ¿äÇÒ¶§ ÀÚµ¿À¸·Î ÀڷḦ °»½ÅÇÏ´Â µ¿Àû ¹Ì·¯°¡ ÇÊ¿äÇÏ´Ù.

ÇØ°áÃ¥:

À̸¦ À§ÇØ Proxy Throughput ±â´ÉÀ» (Ç÷¡±× [P]) »ç¿ëÇÏ¿© ¿ÜºÎ À¥ÆäÀÌÁö ȤÀº ¿ÜºÎ À¥°ø°£ Àüü¸¦ ¿ì¸® À̸§°ø°£À¸·Î ´ëÀÀÇÑ´Ù:

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^hotsheet/(.*)$  http://www.tstimpreso.com/hotsheet/$1  [P]
RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^usa-news\.html$   http://www.quux-corp.com/news/index.html  [P]

µ¿Àû ¿ª¹Ì·¯

»óȲ¼³¸í:
...
ÇØ°áÃ¥:
RewriteEngine on
RewriteCond   /mirror/of/remotesite/$1           -U
RewriteRule   ^http://www\.remotesite\.com/(.*)$ /mirror/of/remotesite/$1

¾ø´Â ÀڷḦ ÀÎÆ®¶ó³Ý¿¡¼­ °¡Á®¿À±â

»óȲ¼³¸í:

½ÇÁ¦ ÀڷḦ ¹æÈ­º®ÀÌ º¸È£ÇÏ´Â (³»ºÎ) ÀÎÆ®¶ó³Ý À¥¼­¹ö¿¡ (www2.quux-corp.dom) ÀúÀåÇϸ鼭, ±â¾÷ÀÇ (¿ÜºÎ) ÀÎÅÍ³Ý À¥¼­¹ö¸¦ (www.quux-corp.dom) ½ÇÇàÇÏ´Â °Íó·³ º¸ÀÌ°Ô ÇÑ´Ù. ¿ÜºÎ À¥¼­¹ö´Â ¿äûÇÑ ÀڷḦ ³»ºÎ À¥¼­¹ö¿¡¼­ °¡Á®¿Â´Ù.

ÇØ°áÃ¥:

¸ÕÀú ¹æÈ­º®ÀÌ ³»ºÎ À¥¼­¹ö¸¦ º¸È£ÇÏ°í ¿ÜºÎ À¥¼­¹ö¸¸ÀÌ ³»ºÎ À¥¼­¹ö¿¡¼­ ÀڷḦ ¾òÀ» ¼ö ÀÖ°Ô ÇÑ´Ù. ´ÙÀ½°ú °°ÀÌ ÆÐŶÇÊÅ͸µ ¹æÈ­º®À» ¼³Á¤ÇÑ´Ù:

ALLOW Host www.quux-corp.dom Port >1024 --> Host www2.quux-corp.dom Port 80
DENY  Host *                 Port *     --> Host www2.quux-corp.dom Port 80

½ÇÁ¦ ¼³Á¤¹®¹ý¿¡ ¾Ë¸Â°Ô °íÃĶó. ¾ø´Â ÀڷḦ ³»ºÎÀûÀ¸·Î proxy throughput ±â´ÉÀ» ÅëÇØ ¿äûÇÏ´Â mod_rewrite ±ÔÄ¢À» ÀÛ¼ºÇÑ´Ù:

RewriteRule ^/~([^/]+)/?(.*)          /home/$1/.www/$2
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^/home/([^/]+)/.www/?(.*) http://www2.quux-corp.dom/~$1/pub/$2 [P]

·Îµå¹ë·±½Ì (ºÎÇÏ ºÐ»êÇϱâ)

»óȲ¼³¸í:

www.foo.comÀÇ Åë½Å·®À» www[0-5].foo.com (ÃÑ ¼­¹ö 6´ë)À¸·Î ºÐ»êÇÏ°í ½Í´Ù. ¾î¶»°Ô Çϴ°¡?

ÇØ°áÃ¥:

¸Å¿ì ´Ù¾çÇÑ ¹æ¹ýÀ¸·Î ÀÌ ¹®Á¦¸¦ ÇØ°áÇÒ ¼ö ÀÖ´Ù. ¸ÕÀú DNS¸¦ »ç¿ëÇÑ Àß ¾Ë·ÁÁø ¹æ¹ýÀ» ¼³¸íÇÏ°í, mod_rewrite¸¦ »ç¿ëÇÏ´Â °æ¿ì¸¦ »ìÆ캸ÀÚ:

  1. DNS Round-Robin

    °¡Àå °£´ÜÇÑ ·Îµå¹ë·±½Ì ¹æ¹ýÀº BINDÀÇ DNS round-robin ¹æ½ÄÀ» »ç¿ëÇÏ´Â °ÍÀÌ´Ù. ´ÙÀ½°ú °°ÀÌ DNS A(address) ·¹Äڵ忡 www[0-9].foo.comÀ» ¼³Á¤ÇÑ´Ù.

    www0   IN  A       1.2.3.1
    www1   IN  A       1.2.3.2
    www2   IN  A       1.2.3.3
    www3   IN  A       1.2.3.4
    www4   IN  A       1.2.3.5
    www5   IN  A       1.2.3.6
    

    ±×¸®°í ´ÙÀ½ Ç׸ñÀ» Ãß°¡ÇÑ´Ù:

    www    IN  CNAME   www0.foo.com.
           IN  CNAME   www1.foo.com.
           IN  CNAME   www2.foo.com.
           IN  CNAME   www3.foo.com.
           IN  CNAME   www4.foo.com.
           IN  CNAME   www5.foo.com.
           IN  CNAME   www6.foo.com.
    

    À߸øµÈ °Íó·³ º¸ÀÌÁö¸¸, ½ÇÁ¦·Î BINDÀÇ ÀǵµµÈ ±â´ÉÀÌ´Ù. ÀÌÁ¦ www.foo.comÀ» ãÀ¸¸é, BIND´Â ¸Å¹ø ¼ø¼­¸¦ Á¶±Ý¾¿ ¹Ù²ã°¡¸ç www0-www6À» ¹ÝȯÇÑ´Ù. ±×·¡¼­ Ŭ¶óÀ̾ðÆ®µéÀ» ¿©·¯ ¼­¹ö·Î ºÐ»êÇÑ´Ù. ±×·¯³ª DNS °Ë»ö °á°ú°¡ ³×Æ®¿÷ÀÇ ´Ù¸¥ ³×ÀÓ¼­¹ö¿¡ ij½¬µÇ¿© www.foo.comÀ» ãÀº °á°ú°¡ ƯÁ¤ wwwN.foo.comÀ̸é Ŭ¶óÀ̾ðÆ®ÀÇ ´ÙÀ½ ¿äûµéµµ °°Àº wwwN.foo.comÀ¸·Î º¸³»Áö±â¶§¹®¿¡ ¿Ïº®ÇÑ ·Îµå¹ë·±½Ì ±â¹ýÀÌ ¾Æ´ÔÀ» ÁÖÀÇÇ϶ó. ±×·¯³ª Å©°Ô º¸¸é ¿äûÀÌ ¿©·¯ À¥¼­¹ö¿¡ ºÐ»êµÇ¹Ç·Î È¿°ú°¡ ÁÁ´Ù.

  2. DNS ·Îµå¹ë·±½Ì

    http://www.stanford.edu/~schemers/docs/lbnamed/lbnamed.html¿¡ ÀÖ´Â lbnamed ÇÁ·Î±×·¥À» »ç¿ëÇÏ¿© Á¤±³ÇÑ DNS±â¹Ý ·Îµå¹ë·±½ÌÀ» ÇÒ ¼ö ÀÖ´Ù. DNS°¡ ½ÇÁ¦ ·Îµå¹ë·±½ÌÀ» Çϵµ·Ï ¸¸µå´Â ¿©·¯ µµ±¸¿Í Perl 5 ÇÁ·Î±×·¥ÀÌ´Ù.

  3. Proxy Throughput Round-Robin

    ÀÌ ¹æ¹ýÀº mod_rewrite¿Í proxy throughput ±â´ÉÀ» »ç¿ëÇÑ´Ù. ¸ÕÀú DNS¿¡ ´ÙÀ½ Ç׸ñÀ» »ç¿ëÇÏ¿© www0.foo.comÀÌ ½ÇÁ¦ www.foo.comÀ» Àü´ãÇÏ°Ô ÇÑ´Ù

    www    IN  CNAME   www0.foo.com.
    

    ±×¸®°í www0.foo.comÀ» ÇÁ·Ï½ÃÀü¿ë ¼­¹ö·Î º¯°æÇÑ´Ù. Áï, URLÀ» ¹ÞÀ¸¸é ¼­¹ö´Â ³»ºÎ ÇÁ·Ï½Ã¸¦ ÅëÇØ ´Ù¸¥ 5´ë ¼­¹öÁß (www1-www5) ÇÑ´ë·Î º¸³»±â¸¸ ÇÑ´Ù. À̸¦ À§ÇØ ¸ÕÀú ¸ðµç URLÀ» ·Îµå¹ë·±½Ì ½ºÅ©¸³Æ® lb.pl·Î º¸³»´Â ±ÔÄ¢À» ¸¸µç´Ù.

    RewriteEngine on
    RewriteMap    lb      prg:/path/to/lb.pl
    RewriteRule   ^/(.+)$ ${lb:$1}           [P,L]
    

    lb.plÀ» ÀÛ¼ºÇÑ´Ù:

    #!/path/to/perl
    ##
    ##  lb.pl -- ·Îµå¹ë·±½Ì ½ºÅ©¸³Æ®
    ##
    
    $| = 1;
    
    $name   = "www";     # ±âº» È£½ºÆ®¸í
    $first  = 1;         # ù¹ø° ¼­¹ö (ÀÚ½ÅÀÌ 0À̱⠶§¹®¿¡, 0À» »ç¿ëÇÏÁö ¾Ê´Â´Ù)
    $last   = 5;         # round-robin¿¡¼­ ¸¶Áö¸· ¼­¹ö
    $domain = "foo.dom"; # µµ¸ÞÀθí
    
    $cnt = 0;
    while (<STDIN>) {
        $cnt = (($cnt+1) % ($last+1-$first));
        $server = sprintf("%s%d.%s", $name, $cnt+$first, $domain);
        print "http://$server/$_";
    }
    
    ##EOF##
    
    ¸¶Áö¸· ÁÖÀÇ: ¿Ö ÀÌ ¹æ¹ýÀÌ À¯¿ëÇÑ°¡? www0.foo.com¿¡ ºÎ´ãÀÌ °¡Áö¾Ê´Â°¡? ¹°·Ð, ºÎ´ãÀÌ µÈ´Ù. ±×·¯³ª ´Ü¼øÇÑ proxy throughput ¿äû¸¸ Çϱ⶧¹®¿¡ ±¦Âú´Ù! ¸ðµç SSI, CGI, ePerl µîÀº ÀüÀûÀ¸·Î ´Ù¸¥ ¼­¹ö°¡ ó¸®ÇÑ´Ù. ÀÌ°ÍÀÌ ÇÙ½ÉÀÌ´Ù.
  4. Çϵå¿þ¾î/TCP Round-Robin

    Çϵå¿þ¾î¸¦ »ç¿ëÇÑ ÇØ°áÃ¥µµ ÀÖ´Ù. Cisco´Â TCP/IP ¼öÁØ¿¡¼­ ·Îµå¹ë·±½ÌÀ» ÇÏ´Â LocalDirector¶ó´Â ±«¹°À» ÆÇ´Ù. ½ÇÁ¦·Î´Â À¥¼­¹ö±º ¾Õ´Ü¿¡ À§Ä¡ÇÏ´Â ÀÏÁ¾ÀÇ È¸·Î¼öÁØ °ÔÀÌÆ®¿þÀÌ´Ù. ÀÚ±ÝÀÌ ÃæºÐÇÏ°í °í¼º´É ÇØ°áÃ¥ÀÌ ÇÊ¿äÇÏ´Ù¸é ÀÌ°ÍÀ» »ç¿ëÇ϶ó.

»õ·Î¿î MIME-type, »õ·Î¿î ¼­ºñ½º

»óȲ¼³¸í:

³×Æ®¿÷¿¡´Â ¸ÚÁø CGI ÇÁ·Î±×·¥µéÀÌ ¸¹´Ù. ±×·¯³ª »ç¿ëÇϱ⠹ø°Å·¯¿ö¼­ ¸¹Àº À¥°ü¸®ÀÚ°¡ »ç¿ëÇÏÁö ¾Ê´Â´Ù. ¾ÆÆÄÄ¡ÀÇ MIME-type¿¡ µû¸¥ Action Çڵ鷯 ±â´Éµµ CGI ÇÁ·Î±×·¥ÀÌ Æ¯º°ÇÑ URLÀ» (Á¤È®È÷ PATH_INFO¿Í QUERY_STRINGS) ÇÁ·Î±×·¥ÀÇ ÀÔ·ÂÀ¸·Î »ç¿ëÇÏÁö ¾ÊÀ» ¶§¸¸ ÀûÀýÇÏ´Ù. ¸ÕÀú, È®ÀåÀÚ°¡ (secure CGI¸¦ ÁÙ¿©) .scgiÀÎ ÆÄÀÏÀ» À¯¸íÇÑ cgiwrap ÇÁ·Î±×·¥À¸·Î ó¸®ÇϱâÀ§ÇØ »õ·Î¿î typeÀ» ¼³Á¤ÇÑ´Ù. ¹®Á¦´Â (À§¿¡¼­ º») ÀÏ°üµÈ URL ±¸Á¶¸¦ »ç¿ëÇÏ´Â °æ¿ì »ç¿ëÀÚ È¨µð·ºÅ丮°¡ /u/user/foo/bar.scgi°°Àº URLÀÎ Á¡ÀÌ´Ù. cgiwrap´Â /~user/foo/bar.scgi/ Çü½ÄÀÇ URLÀ» ¿øÇϱ⶧¹®ÀÌ´Ù. ´ÙÀ½ ±ÔÄ¢ÀÌ ¹®Á¦¸¦ ÇØ°áÇÑ´Ù:

RewriteRule ^/[uge]/([^/]+)/\.www/(.+)\.scgi(.*) ...
... /internal/cgi/user/cgiwrap/~$1/$2.scgi$3  [NS,T=application/x-http-cgi]

ÀÌÁ¦ ´Ù¸¥ ¸ÚÁø ÇÁ·Î±×·¥, (URL ÇÏÀ§Æ®¸®¿¡ ´ëÇÑ access.log¸¦ Ãâ·ÂÇÏ´Â) wwwlog¿Í (URL ÇÏÀ§Æ®¸®¿¡ Glimpse¸¦ ½ÇÇàÇÏ´Â) wwwidx°¡ ÀÖ´Ù°í °¡Á¤ÇÏÀÚ. ¿ì¸®´Â ÇÁ·Î±×·¥¿¡°Ô ÀÛ¾÷ÇÒ ´ë»óÀÎ URL ¿µ¿ªÀ» ¾Ë·ÁÁà¾ß ÇÑ´Ù. ±×·¯³ª ¿äûÇÒ¶§¸¶´Ù Ç×»ó Àû¾îÁà¾ß Çϱ⶧¹®¿¡ ±ò²ûÇÏÁö ¾Ê´Ù. Áï, º¸Åë /u/user/foo/¿¡ ´ëÇØ swwidx ÇÁ·Î±×·¥À» ½ÇÇàÇÑ´Ù¸é ´ÙÀ½°ú °°Àº ¸µÅ©¸¦ »ç¿ëÇÑ´Ù

/internal/cgi/user/swwidx?i=/u/user/foo/

±ò²ûÇÏÁö ¾Ê´Ù. ¸µÅ©¿¡ ¿µ¿ªÀÇ À§Ä¡¿Í CGI À§Ä¡¸¦ ¸ðµÎ Àû¾î¾ß Çϱ⶧¹®ÀÌ´Ù. ¿µ¿ªÀ» À籸¼ºÇÑ´Ù¸é ¿©·¯ ÇÏÀÌÆÛ¸µÅ©¸¦ ¼öÁ¤Çϴµ¥ ¸¹Àº ½Ã°£ÀÌ °É¸± °ÍÀÌ´Ù.

ÇØ°áÃ¥:

ÇØ°áÃ¥Àº ÀÚµ¿À¸·Î ÀûÀýÇÑ CGI¸¦ ½ÇÇàÇÏ´Â »õ·Î¿î Ưº°ÇÑ URL Çü½ÄÀ» ¸¸µå´Â °ÍÀÌ´Ù. ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÑ´Ù:

RewriteRule   ^/([uge])/([^/]+)(/?.*)/\*  /internal/cgi/user/wwwidx?i=/$1/$2$3/
RewriteRule   ^/([uge])/([^/]+)(/?.*):log /internal/cgi/user/wwwlog?f=/$1/$2$3

ÀÌÁ¦ /u/user/foo/À» °Ë»öÇÏ´Â ¸µÅ©´Â ´ÙÀ½°ú °°´Ù

HREF="*"
/u/user/foo/* (???)

³»ºÎÀûÀ¸·Î ´ÙÀ½°ú °°ÀÌ ÀÚµ¿º¯È¯µÈ´Ù

/internal/cgi/user/wwwidx?i=/u/user/foo/

°°Àº ¹æ¹ýÀ¸·Î ¸µÅ© µÚ¿¡ :log¸¦ »ç¿ëÇÏ¿© Á¢±Ù ·Î±× CGI ÇÁ·Î±×·¥À» ½ÇÇàÇÒ ¼ö ÀÖ´Ù.

Á¤Àû¿¡¼­ µ¿ÀûÀ¸·Î

»óȲ¼³¸í:

¾î¶»°Ô ºê¶ó¿ìÀú¿Í »ç¿ëÀÚ°¡ ¸ð¸£°Ô ÀÚ¿¬½º·´°Ô Á¤Àû ÆäÀÌÁö foo.htmlÀ» µ¿ÀûÀÎ foo.cgi·Î º¯°æÇÒ ¼ö ÀÖ³ª.

ÇØ°áÃ¥:

URLÀ» CGI ½ºÅ©¸³Æ®·Î ÀçÀÛ¼ºÇÏ°í, MIME-typeÀ» ¼öÁ¤ÇÏ¿© CGI ½ºÅ©¸³Æ®·Î ½ÇÇàÇÏ°Ô ÇÑ´Ù. ±×·¡¼­ /~quux/foo.html¸¦ ¿äûÇÏ¸é ³»ºÎÀûÀ¸·Î /~quux/foo.cgi¸¦ ½ÇÇàÇÏ°Ô µÈ´Ù.

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo\.html$  foo.cgi  [T=application/x-httpd-cgi]

Áï¼® ÄÁÅÙÃ÷ Àç»ý¼º

»óȲ¼³¸í:

ÀÌ ¹æ¹ýÀº ½Ç·Î ºñ±âÀÌ´Ù: µ¿ÀûÀ¸·Î ÆäÀÌÁö¸¦ »ý¼ºÇÏÁö¸¸, Á¤ÀûÀ¸·Î ÆäÀÌÁö¸¦ ¼­ºñ½ºÇÑ´Ù. Áï, ÆäÀÌÁö´Â ¼ø¼öÇÏ°Ô (ÆÄÀϽýºÅÛ¿¡¼­ ÀÐÀº ³»¿ëÀ» ±×´ë·Î) Á¤Àû ÆäÀÌÁö·Î Àü´ÞµÇÁö¸¸, ¾øÀ» °æ¿ì À¥¼­¹ö°¡ µ¿ÀûÀ¸·Î »ý¼ºÇÑ´Ù. ±×·¯¸é ´©°¡ (ȤÀº cron ÀÛ¾÷ÀÌ) Á¤Àû ÄÁÅÙÃ÷¸¦ Áö¿ìÁö¾Ê´Â ÇÑ CGI°¡ »ý¼ºÇÑ ÆäÀÌÁö¸¦ Á¤ÀûÀ¸·Î ¼­ºñ½ºÇÑ´Ù. ÄÁÅÙÃ÷¸¦ Áö¿ì¸é ³»¿ëÀ» °»½ÅÇÑ´Ù.

ÇØ°áÃ¥:
´ÙÀ½ ±ÔÄ¢À» »ç¿ëÇÑ´Ù:
RewriteCond %{REQUEST_FILENAME}   !-s
RewriteRule ^page\.html$          page.cgi   [T=application/x-httpd-cgi,L]

¿©±â¼­ page.html¸¦ ¿äûÇÒ¶§ page.htmlÀÌ ¾ø°Å³ª ÆÄÀÏÅ©±â°¡ 0ÀÎ °æ¿ì ³»ºÎÀûÀ¸·Î page.cgi¸¦ ½ÇÇàÇÑ´Ù. ¿©±â¼­ ºñ°áÀº page.cgi°¡ ÀϹÝÀûÀÎ CGI ½ºÅ©¸³Æ®¿Í °°ÀÌ STDOUT¿¡ Ãâ·ÂÇÏ°í, Ãß°¡·Î Ãâ·ÂÀ» page.html ÆÄÀÏ¿¡ Àû´Â´Ù. Çѹø ½ÇÇàÇÑÈÄ ¼­¹ö´Â page.htmlÀÇ Á¤º¸¸¦ º¸³½´Ù. À¥°ü¸®ÀÚ°¡ °­Àç·Î ³»¿ëÀ» °»½ÅÇÏ°í ½Í´Ù¸é, (º¸Åë cron ÀÛ¾÷ÀÌ) page.htmlÀ» Áö¿ì±â¸¸ ÇÏ¸é µÈ´Ù.

ÀÚµ¿À¸·Î »õ·Î °íħÇÏ´Â ¹®¼­

»óȲ¼³¸í:

º¹ÀâÇÑ À¥ÆäÀÌÁö¸¦ ¸¸µé¶§ ÆíÁýÀÚ°¡ ³»¿ëÀ» ¼öÁ¤ÇÒ ¶§¸¶´Ù ÀÚµ¿À¸·Î ÆäÀÌÁö¸¦ »õ·Î °íħÇÏ´Â À¥ºê¶ó¿ìÀú°¡ ÀÖÀ¸¸é ¾ó¸¶³ª ÁÁÀ»±î? ºÒ°¡´ÉÇÑ°¡?

ÇØ°áÃ¥:

°¡´ÉÇÏ´Ù! MIME multipart ±â´É°ú À¥¼­¹ö NPH ±â´É, mod_rewriteÀÇ URL Á¶ÀÛ ´É·ÂÀ» °áÇÕÇÏ¸é µÈ´Ù. ¸ÕÀú, »õ·Î¿î URL ±â´ÉÀ» ¸¸µç´Ù: URL¿¡ :refresh¸¦ Ãß°¡Çϱ⸸ Çϸé ÆÄÀϽýºÅÛ¿¡¼­ ¼öÁ¤µÉ ¶§¸¶´Ù »õ·Î °íħÇÑ´Ù.

RewriteRule   ^(/[uge]/[^/]+/?.*):refresh  /internal/cgi/apache/nph-refresh?f=$1

ÀÌÁ¦ ´ÙÀ½ URL¿¡ Á¢±ÙÇϸé

/u/foo/bar/page.html:refresh

´ÙÀ½ URLÀ» ³»ºÎÀûÀ¸·Î ºÎ¸¥´Ù

/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html

ÀÌÁ¦ NPH-CGI ½ºÅ©¸³Æ®¸¸ ³²¾Ò´Ù. º¸Åë "µ¶ÀÚ¿¡°Ô ¿¬½ÀÀ¸·Î ³²°ÜµÒ"À̶ó°í ¸»ÇÏÁö¸¸ ;-) ³ª´Â À̰͵µ Á¦°øÇÑ´Ù.

#!/sw/bin/perl
##
##  nph-refresh -- NPH/CGI script for auto refreshing pages
##  Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
##
$| = 1;

#   split the QUERY_STRING variable
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $name =~ tr/A-Z/a-z/;
    $name = 'QS_' . $name;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    eval "\$$name = \"$value\"";
}
$QS_s = 1 if ($QS_s eq '');
$QS_n = 3600 if ($QS_n eq '');
if ($QS_f eq '') {
    print "HTTP/1.0 200 OK\n";
    print "Content-type: text/html\n\n";
    print "&lt;b&gt;ERROR&lt;/b&gt;: No file given\n";
    exit(0);
}
if (! -f $QS_f) {
    print "HTTP/1.0 200 OK\n";
    print "Content-type: text/html\n\n";
    print "&lt;b&gt;ERROR&lt;/b&gt;: File $QS_f not found\n";
    exit(0);
}

sub print_http_headers_multipart_begin {
    print "HTTP/1.0 200 OK\n";
    $bound = "ThisRandomString12345";
    print "Content-type: multipart/x-mixed-replace;boundary=$bound\n";
    &print_http_headers_multipart_next;
}

sub print_http_headers_multipart_next {
    print "\n--$bound\n";
}

sub print_http_headers_multipart_end {
    print "\n--$bound--\n";
}

sub displayhtml {
    local($buffer) = @_;
    $len = length($buffer);
    print "Content-type: text/html\n";
    print "Content-length: $len\n\n";
    print $buffer;
}

sub readfile {
    local($file) = @_;
    local(*FP, $size, $buffer, $bytes);
    ($x, $x, $x, $x, $x, $x, $x, $size) = stat($file);
    $size = sprintf("%d", $size);
    open(FP, "&lt;$file");
    $bytes = sysread(FP, $buffer, $size);
    close(FP);
    return $buffer;
}

$buffer = &readfile($QS_f);
&print_http_headers_multipart_begin;
&displayhtml($buffer);

sub mystat {
    local($file) = $_[0];
    local($time);

    ($x, $x, $x, $x, $x, $x, $x, $x, $x, $mtime) = stat($file);
    return $mtime;
}

$mtimeL = &mystat($QS_f);
$mtime = $mtime;
for ($n = 0; $n &lt; $QS_n; $n++) {
    while (1) {
        $mtime = &mystat($QS_f);
        if ($mtime ne $mtimeL) {
            $mtimeL = $mtime;
            sleep(2);
            $buffer = &readfile($QS_f);
            &print_http_headers_multipart_next;
            &displayhtml($buffer);
            sleep(5);
            $mtimeL = &mystat($QS_f);
            last;
        }
        sleep($QS_s);
    }
}

&print_http_headers_multipart_end;

exit(0);

##EOF##

´ë·®ÀÇ °¡»óÈ£½ºÆ®

»óȲ¼³¸í:

°¡»óÈ£½ºÆ®°¡ ¸î°³¸¸ ÀÖ´Ù¸é ¾ÆÆÄÄ¡ÀÇ <VirtualHost> ±â´ÉÀÌ Àß µ¿ÀÛÇÑ´Ù. ±×·¯³ª °¡»óÈ£½ºÆ®°¡ ¼ö¹é°³ ÀÖ´Â ISP¶ó¸é ÀÌ ±â´ÉÀÌ ÃÖ¼±Àº ¾Æ´Ï´Ù.

ÇØ°áÃ¥:

ÀÌ ±â´ÉÀ» Á¦°øÇÏ·Á¸é Proxy Throughput ±â´ÉÀ» (Ç÷¡±× [P]) »ç¿ëÇÏ¿© ¿ÜºÎ À¥ÆäÀÌÁö ȤÀº Àüü ¿ÜºÎ À¥¿µ¿ªÀ» ¿ì¸®ÀÇ À̸§°ø°£¿¡ ´ëÀÀÇÑ´Ù:

##
##  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
##
##  apache2.conf
##
    :
#   ¸®´ÙÀÌ·ºÆ®ÇÒ¶§ Á¤±Ô È£½ºÆ®¸íÀ» »ç¿ëÇÑ´Ù.
UseCanonicalName on

    :
#   °¡»óÈ£½ºÆ®¸¦ CLF Çü½Ä ¾Õ¿¡ Ãß°¡ÇÑ´Ù
CustomLog  /path/to/access_log  "%{VHOST}e %h %l %u %t \"%r\" %>s %b"
    :

#   ÁÖ¼­¹ö¿¡¼­ ÀçÀÛ¼º ¿£ÁøÀ» »ç¿ëÇÑ´Ù
RewriteEngine on

#   µÎ ¸ÊÀ» Á¤ÀÇÇÑ´Ù: Çϳª´Â URLÀ» °íÄ¡°í,
#   ´Ù¸¥ Çϳª´Â °¡»óÈ£½ºÆ®º° DocumentRoot¸¦
#   Á¤ÀÇÇÑ´Ù.
RewriteMap    lowercase    int:tolower
RewriteMap    vhost        txt:/path/to/vhost.map

#   ÀÌÁ¦ Å©°í º¹ÀâÇÑ ±ÔÄ¢ ÇÑ°³¸¦ »ç¿ëÇÏ¿©
#   °¡»óÈ£½ºÆ®·Î ´ëÀÀÇÑ´Ù.
#
#   1. °¡»óÈ£½ºÆ®µéÀÌ °°ÀÌ »ç¿ëÇÏ´Â À§Ä¡´Â ´ëÀÀÇÏÁö ¾Ê´Â´Ù
RewriteCond   %{REQUEST_URL}  !^/commonurl1/.*
RewriteCond   %{REQUEST_URL}  !^/commonurl2/.*
    :
RewriteCond   %{REQUEST_URL}  !^/commonurlN/.*
#
#   2. ¿ì¸®°¡ ÇöÀç »ç¿ëÇÏ´Â ¹æ¹ýÀÌ Host Çì´õ¸¦
#      °¡»óÈ£½ºÆ®¸¦ Áö¿øÇϹǷÎ
#      Host Çì´õ°¡ ÀÖ´ÂÁö È®ÀÎÇÑ´Ù
RewriteCond   %{HTTP_HOST}  !^$
#
#   3. È£½ºÆ®¸íÀ» ¼Ò¹®ÀÚ·Î ¸¸µç´Ù
RewriteCond   ${lowercase:%{HTTP_HOST}|NONE}  ^(.+)$
#
#   4. vhost.map¿¡¼­ È£½ºÆ®¸íÀ» ã°í
#      °æ·ÎÀ϶§¸¸ ±â¾ïÇÑ´Ù
#      (À§¿¡¼­ "NONE"Àº ¾Æ´Ï´Ù)
RewriteCond   ${vhost:%1}  ^(/.*)$
#
#   5. ¸¶Áö¸·À¸·Î URLÀ» ¹®¼­ À§Ä¡·Î ´ëÀÀÇÏ°í
#      ·Î±×¿¡ ³²±â±âÀ§ÇØ °¡»óÈ£½ºÆ®¸¦ ±â¾ïÇØ µÐ´Ù
RewriteRule   ^/(.*)$   %1/$1  [E=VHOST:${lowercase:%{HTTP_HOST}}]
    :
top

Á¢±Ù Á¦ÇÑ

·Îº¿ ¸·±â

»óȲ¼³¸í:

¾î¶»°Ô Çϸé ƯÁ¤ À¥°ø°£ÀÇ ÆäÀÌÁö¸¦ ±Ü¾î¸ðÀ¸´Â ±ÍÂúÀº ·Îº¿À» ¸·À» ¼ö ÀÖ³ª? "Robot Exclusion Protocol" Ç׸ñÀ» ÀúÀåÇÑ /robots.txt ÆÄÀÏÀº º¸Åë ÀÌ·± ·Îº¿À» ¸·´Âµ¥ ÃæºÐÇÏÁö ¾Ê´Ù.

ÇØ°áÃ¥:

(¾Æ¸¶µµ µð·ºÅ丮°¡ ±í¾î¼­ ·Îº¿ÀÌ µ¹¾Æ´Ù´Ï¸é ¼­¹ö¿¡ ºÎ´ãÀÌ Å« °æ¿ì) À¥°ø°£ /~quux/foo/arc/¿¡ ÀÖ´Â URLµéÀ» °ÅºÎÇÏ´Â ±ÔÄ¢À» »ç¿ëÇÑ´Ù. ¿ì¸®´Â ƯÁ¤ ·Îº¿ÀÇ Á¢±ÙÀ» ¸·¾Æ¾ß ÇÑ´Ù. Áï, ·Îº¿À» ½ÇÇàÇϴ ȣ½ºÆ®¸¦ ¸·´Â °ÍÀ¸·Î´Â ºÒÃæºÐÇϸç, ±× È£½ºÆ®ÀÇ »ç¿ëÀÚµµ ¸·¾Æ¹ö¸®°Ô µÈ´Ù. User-Agent HTTP Çì´õ Á¤º¸µµ ºñ±³ÇÑ´Ù.

RewriteCond %{HTTP_USER_AGENT}   ^NameOfBadRobot.*
RewriteCond %{REMOTE_ADDR}       ^123\.45\.67\.[8-9]$
RewriteRule ^/~quux/foo/arc/.+   -   [F]

±×¸² ÆÛ°¡±â ¹æÁö

»óȲ¼³¸í:

http://www.quux-corp.de/~quux/¿¡ ÀÖ´Â ÆäÀÌÁöµéÀÌ GIF ±×¸²À» Æ÷ÇÔÇÑ´Ù°í °¡Á¤ÇÏÀÚ. ÀÌ ±×¸²ÀÌ ¸ÚÀ־, ´Ù¸¥ »ç¶÷µéÀÌ ÀÚ½ÅÀÇ ÆäÀÌÁö¿¡ Á÷Á¢ ¸µÅ©¸¦ °Ç´Ù. ¼­¹ö¿¡ ºÒÇÊ¿äÇÑ ºÎ´ãÀÌ µÇ¹Ç·Î ¸·°í ½Í´Ù.

ÇØ°áÃ¥:

±×¸²À» 100% º¸È£ÇÒ ¼ö´Â ¾øÁö¸¸, ÃÖ¼ÒÇÑ ºê¶ó¿ìÀú°¡ HTTP Referer Çì´õ¸¦ º¸³»´Â °æ¿ì Á¦ÇÑÇÒ ¼ö ÀÖ´Ù.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC]
RewriteRule .*\.gif$        -                                    [F]
RewriteCond %{HTTP_REFERER}         !^$
RewriteCond %{HTTP_REFERER}         !.*/foo-with-gif\.html$
RewriteRule ^inlined-in-foo\.gif$   -                        [F]

È£½ºÆ® °ÅºÎ

»óȲ¼³¸í:

¾î¶»°Ô ¿ÜºÎ¿¡¼­ ¼­¹ö¿¡ Á¢±ÙÇÒ ¼ö ¾ø´Â È£½ºÆ® ¸ñ·ÏÀ» ¼³Á¤ÇÒ ¼ö ÀÖ³ª?

ÇØ°áÃ¥:

¾ÆÆÄÄ¡ >= 1.3b6¿¡¼­:

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]

¾ÆÆÄÄ¡ <= 1.3b6¿¡¼­:

RewriteEngine on
RewriteMap    hosts-deny  txt:/path/to/hosts.deny
RewriteRule   ^/(.*)$ ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND}/$1
RewriteRule   !^NOT-FOUND/.* - [F]
RewriteRule   ^NOT-FOUND/(.*)$ ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND}/$1
RewriteRule   !^NOT-FOUND/.* - [F]
RewriteRule   ^NOT-FOUND/(.*)$ /$1
##
##  hosts.deny
##
##  ÁÖÀÇ! ÀÌ°ÍÀº ¸ñ·Ïó·³ º¸ÀÌÁö¸¸ ¸ñ·ÏÀÌ ¾Æ´Ï¶ó ¸ÊÀÌ´Ù.
##        mod_rewrite´Â ÀÌ Á¤º¸¸¦ Å°/°ª ½ÖÀ¸·Î Çؼ®Çϱ⶧¹®¿¡,
##        °¢ Ç׸ñÀÇ °ª ÀÚ¸®¿¡ ÃÖ¼ÒÇÑ "-"°¡ ÇÊ¿äÇÏ´Ù.
##

193.102.180.41 -
bsdti1.sdm.de  -
192.76.162.40  -

ÇÁ·Ï½Ã °ÅºÎ

»óȲ¼³¸í:

¾î¶»°Ô ƯÁ¤ È£½ºÆ® ȤÀº ƯÁ¤ È£½ºÆ®ÀÇ »ç¿ëÀÚ°¡ ¾ÆÆÄÄ¡ ÇÁ·Ï½Ã¸¦ »ç¿ëÇÒ ¼ö ¾øµµ·Ï Çϳª?

ÇØ°áÃ¥:

¸ÕÀú ¾ÆÆÄÄ¡ À¥¼­¹ö¸¦ ÄÄÆÄÀÏÇÒ¶§ ±¸¼ºÆÄÀÏ¿¡¼­ mod_rewrite°¡ mod_proxy ¾Æ·¡¿¡(!) ÀÖ¾î¾ß ÇÑ´Ù. ±×·¯¸é mod_rewrite´Â mod_proxy ÀÌÀü¿¡ ºÒ¸°´Ù. ÀÌÁ¦ ´ÙÀ½°ú °°ÀÌ Æ¯Á¤ È£½ºÆ®¸¦ °ÅºÎÇϵµ·Ï ¼³Á¤ÇÑ´Ù...

RewriteCond %{REMOTE_HOST} ^badhost\.mydomain\.com$
RewriteRule !^http://[^/.]\.mydomain.com.*  - [F]

...±×¸®°í ´ÙÀ½Àº user@host¿¡ µû¶ó °ÅºÎÇÑ´Ù:

RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST}  ^badguy@badhost\.mydomain\.com$
RewriteRule !^http://[^/.]\.mydomain.com.*  - [F]

Ưº°ÇÑ ÀÎÁõ ¹æ½Ä

»óÈ°¼³¸í:

°¡²û ¸Å¿ì Ưº°ÇÑ ÀÎÁõÀÌ ÇÊ¿äÇÒ ¶§°¡ ÀÖ´Ù. ¿¹¸¦ µé¾î, ¹Ì¸® ¼³Á¤ÇصР»ç¿ëÀÚÀÎÁö °Ë»çÇÑ´Ù. À̵鿡°Ô¸¸ (mod_auth_basicÀÇ Basic Auth¸¦ »ç¿ëÇÑ °æ¿ì¿Í ´Þ¸®) º°´Ù¸¥ ¹°À½¾øÀÌ Á¢±ÙÀ» Çã¿ëÇÑ´Ù.

ÇØ°áÃ¥:

Ä£±¸¸¸ Á¢±ÙÀÌ °¡´ÉÇϵµ·Ï ÀçÀÛ¼º ±ÔÄ¢µéÀ» »ç¿ëÇÑ´Ù:

RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^[email protected]\.com$
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend2@client2.quux-corp\.com$
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend3@client3.quux-corp\.com$
RewriteRule ^/~quux/only-for-friends/      -                                 [F]

Referer±â¹Ý º¯È¯±â(deflector)

»óȲ¼³¸í:

"Referer" HTTP Çì´õ¿¡ µû¶ó ¿øÇϴ´ë·Î ÂüÁ¶ÆäÀÌÁö¸¦ ¼³Á¤ÇÒ ¼ö ÀÖ´Â À¯¿¬ÇÑ URL º¯È¯±â¸¦ ¸¸µé ¼ö Àִ°¡?

ÇØ°áÃ¥:

´ÙÀ½°ú °°ÀÌ º¹ÀâÇÑ ±ÔÄ¢À»...

RewriteMap  deflector txt:/path/to/deflector.map

RewriteCond %{HTTP_REFERER} !=""
RewriteCond ${deflector:%{HTTP_REFERER}} ^-$
RewriteRule ^.* %{HTTP_REFERER} [R,L]

RewriteCond %{HTTP_REFERER} !=""
RewriteCond ${deflector:%{HTTP_REFERER}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^.* ${deflector:%{HTTP_REFERER}} [R,L]

... ÀçÀÛ¼º ¸Ê°ú °°ÀÌ »ç¿ëÇÑ´Ù:

##
##  deflector.map
##

http://www.badguys.com/bad/index.html    -
http://www.badguys.com/bad/index2.html   -
http://www.badguys.com/bad/index3.html   http://somewhere.com/

±×·¯¸é ¿äûÀ» ÀÚµ¿À¸·Î (¸Ê¿¡¼­ °ªÀ¸·Î "-"¸¦ »ç¿ëÇÑ °æ¿ì) ÂüÁ¶ÆäÀÌÁö³ª (URLÀÌ ¸Ê¿¡ ÀÖ´Â °æ¿ì µÎ¹ø° ¾Æ±Ô¸ÕÆ®·Î) ƯÁ¤ URL·Î ¸®´ÙÀÌ·º¼ÇÇÑ´Ù.

top

±âŸ

¿ÜºÎ ÀçÀÛ¼º ¿£Áø

»óȲ¼³¸í:

FAQ: ¾î¶»°Ô ÀÌ·±Àú·± Àâ´ÙÇÑ ¹®Á¦¸¦ Ç® ¼ö Àִ°¡? mod_rewrite·Î´Â ÇØ°áÃ¥ÀÌ ¾Èº¸ÀδÙ...

ÇØ°áÃ¥:

¿ÜºÎ RewriteMapÀ» »ç¿ëÇ϶ó. Áï, ÇÁ·Î±×·¥ÀÌ RewriteMap ¿ªÇÒÀ» ÇÑ´Ù. ÇÁ·Î±×·¥Àº ¾ÆÆÄÄ¡°¡ ½ÃÀÛÇÒ¶§ ½ÃÀÛÇÏ¿© STDIN¿¡¼­ ¿äûÇÑ URLÀ» ¹Þ°í, (°°Àº ¼ø¼­·Î!) °á°ú (º¸Åë ÀçÀÛ¼ºµÈ) URLÀ» STDOUT¿¡ Ãâ·ÂÇÑ´Ù.

RewriteEngine on
RewriteMap    quux-map       prg:/path/to/map.quux.pl
RewriteRule   ^/~quux/(.*)$  /~quux/${quux-map:$1}
#!/path/to/perl

#   ¾ÆÆÄÄ¡ ¼­¹ö°¡ ¸ØÃßÁö ¾Êµµ·Ï
#   ÀÔÃâ·Â ¹öÆÛ¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù
$| = 1;

#   stdin¿¡¼­ ÇÑÁÙ¾¿ URLÀ» Àаí
#   stdout¿¡ º¯È¯ÇÑ URLÀ» Ãâ·ÂÇÑ´Ù
while (<>) {
    s|^foo/|bar/|;
    print $_;
}

¼³¸íÇϱâÀ§ÇØ ¸ðµç /~quux/foo/... URLÀ» /~quux/bar/...·Î ÀçÀÛ¼ºÇÏ´Â ½ºÅ©¸³Æ®¸¦ ¿¹·Î µé¾ú´Ù. ½ÇÁ¦·Î ¸¶À½´ë·Î ÇÁ·Î±×·¡¹ÖÇÒ ¼ö ÀÖ´Ù. ±×·¯³ª ÀÏ¹Ý »ç¿ëÀÚ°¡ ÀÌ·± ¸ÊÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù°í ÇÏ´õ¶ó°í, ¿ÀÁ÷ ½Ã½ºÅÛ °ü¸®ÀÚ¸¸ÀÌ ¸ÊÀ» Á¤ÀÇÇØ¾ß ÇÔÀ» ÁÖÀÇÇ϶ó.

°¡´ÉÇÑ ¾ð¾î:  en  |  ko