<-
Apache > HTTP Server > Documentation > Version 2.5 > Rewrite

mod_rewriteë¥� �¬ì�©í�� ���� ���� ê°��� �¸ì�¤í��

°¡´ÉÇÑ ¾ð¾î:  de  |  en  |  es  |  fr  |  ja  |  ko  |  tr  |  zh-cn 

�� 문ì���� mod_rewrite 참조 문ì��ë¥� ë³´ì¶©�©ë����. mod_rewriteë¥� �¬ì�©í���� �����¼ë� 구ì�±ë�� ê°��� �¸ì�¤í�¸ë�� ë§����� ë°©ë��� �¤ë��©ë����.

mod_rewrite�� ë³´í�� ê°��� �¸ì�¤í�¸ë�� 구ì�±í���� ìµ����� ë°©ë��� ��������. mod_rewrite�� ��ì¡´í��ê¸� ���� 먼ì�� ������ ê³��¤í�´ì�� �©ë����. "mod_rewriteë¥� �¼í���� ë°©ë�" 문ì���� 참조��������.

Âü°í

top

���� �¸ì�¤í�¸ë��� ���� ê°��� �¸ì�¤í��

�¤ë�:

��ë¡��� VirtualHost �¹ì���� ë§��¤ì� ��ê³� ��ë©��¸ì���� �´ì������ 모ë�� �¸ì�¤í�¸ë��� ���� �����¼ë� ê°��� �¸ì�¤í�¸ë�� ë§��¤ê��� �©ë����.

�� �����¼ì������ ê°� �¬ì�©ì���� ���� �¸ì�¤í�¸ë� SITE.example.com�� �¬ì�©í��ê³� /home/SITE/www���� ì½���ì¸�ë¥� ��ê³µí���¤ê� ê°����©ë����. ê·¸ë�¬ë�� www.example.com�� �� 매í������ ���¸í��ê³��� �©ë����.

�´ê²°ì±�:
RewriteEngine on

RewriteMap    lowercase int:tolower

RewriteCond   %{HTTP_HOST} !^www\.
RewriteCond   ${lowercase:%{HTTP_HOST}}   ^([^.]+)\.example\.com$
RewriteRule   ^(.*)    /home/%1/www$1
���
DNS �´ì���� ì§��� ê´�리í�´ì�� �©ë���� - Apache�� �´ë� �´ì���� ì²�리í��ì§� ���µë����. ê°� �¸ì�¤í�¸ë��� ���� CNAME ��ì½��� ���� DNS ���¼ë��ì¹´ë�� ��ì½���ë¥� ë§��¤ì�´ì�� �©ë����. DNS ��ì½��� ���±ì�� �� 문ì���� ë²���ë¥� ë²��´ë�©ë����.

�´ë� tolower RewriteMap ì§����´ë�� �¬ì�©ë���� �¸ì�¤í�¸ë��� 모ë�� ��문ì���¸ì� ���¸í���� ���±í�´ì�� ���� ������ë¦� 구조�� 모í�¸í�¨ì�� ����ë¡� �©ë����.

RewriteCond���� �¬ì�©ë�� ê´��¸ë�� ��참조 %1, %2 �±ì�¼ë� 캡ì���ë©�, RewriteRule���� �¬ì�©ë�� ê´��¸ë�� ��참조 $1, $2 �±ì�¼ë� 캡ì��©ë����.

ì²� ë²�ì§� RewriteCond�� �¸ì�¤í�¸ë��� www.ë¡� ��������ì§� ���¸í��ê³�, ê·¸ë���¤ë©´ �¬ì���±ì�� ê±´ë���°ì�´ì�����.

�� 문ì������ �¼ì���� ë§��� 기ì��ê³� ë§�ì°¬ê�ì§�ë¡�, mod_rewrite�� �¤ì��ë¡� �� ������ �������� ìµ����� ë°©ë��� ��������. ���� mod_vhost_alias �¬ì�©ì�� ê³��¤í�´ì�� �©ë����. �� 모ë���� ���� ì½���ì¸��� Alias �´ì�� �� ���� ���� ��ê³� �´ì���� 모ë�� ê²��� �¨ì�� �� �°ì����ê²� ì²�리í�©ë����.

top

mod_rewriteë¥� �¬ì�©í�� ���� ê°��� �¸ì�¤í��

httpd.conf������ �� ë°�ì·��� ì²� ë²�ì§� ������ ���¼í�� ������ �����©ë����. ��ë°�ë¶��� ���� �´ë�� ë¶�ë¶�ê³� 매ì�� ���¬í��ì§�ë§� ���� �¸í���±ì�� ���� 그리ê³� mod_rewrite ë¶�ë¶��� �¬ë�르ê� ��������ë¡� ������ �¼ë� ë³�ê²½ì�� ���µë����. ��ë°�ë¶��� �¤ì�� ������ ��������ë¡� mod_rewriteë¥� 구ì�±í�©ë����.

mod_rewrite�� �¤ë¥¸ URI ë³��� 모ë��(��: mod_alias) ���� �¤í����ë¯�ë¡�, mod_rewrite��ê²� ê·¸ë�¬í�� 모ë���� ì²�리í���� URL�� ëª������¼ë� 무ì������ë¡� ì§����´ì�� �©ë����. ���� �� ê·�ì¹��� ScriptAlias ì§����´ë�� �°í����ë¯�ë¡� mod_rewriteê°� �´ë�¬í�� 매í���� ëª������¼ë� ��������ë¡� �´ì�� �©ë����.

# get the server name from the Host: header
UseCanonicalName Off

# splittable logs
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" vcommon
CustomLog "logs/access_log" vcommon

<Directory "/www/hosts">
    # ExecCGI is needed here because we can't force
    # CGI execution in the way that ScriptAlias does
    Options FollowSymLinks ExecCGI
</Directory>

RewriteEngine On

# a ServerName derived from a Host: header may be any case at all
RewriteMap  lowercase  "int:tolower"

## deal with normal documents first:
# allow Alias /icons/ to work - repeat for other aliases
RewriteCond  "%{REQUEST_URI}"  "!^/icons/"
# allow CGIs to work
RewriteCond  "%{REQUEST_URI}"  "!^/cgi-bin/"
# do the magic
RewriteRule  "^/(.*)$"         "/www/hosts/${lowercase:%{SERVER_NAME}}/docs/$1"

## and now deal with CGIs - we have to force a handler
RewriteCond  "%{REQUEST_URI}"  "^/cgi-bin/"
RewriteRule  "^/(.*)$"         "/www/hosts/${lowercase:%{SERVER_NAME}}/cgi-bin/$1"  [H=cgi-script]
top

ë³����� ê°��� �¸ì�¤í�� �¤ì�� ���� �¬ì��

�� ë°°ì��� �� ê³�ê¸� mod_rewrite 기ë�¥ì�� �¬ì�©í���� ë³����� �¤ì�� ���¼ì���� ê°��� �¸ì�¤í�¸ì���� 문ì�� 루í�¸ë��� ë³����� �����©ë����. �´ë�� �� ë§��� ���°ì�±ì�� ��ê³µí��ì§�ë§� �� ë³µì�¡í�� �¤ì���� �����©ë����.

vhost.map ���¼ì�� �¤ì��ê³� ê°��� �����¬ì�� �©ë����:

customer-1.example.com /www/customers/1
customer-2.example.com /www/customers/2
# ...
customer-N.example.com /www/customers/N

httpd.conf���� �¤ì���� �¬í�¨ë���´ì�� �©ë����:

RewriteEngine on

RewriteMap   lowercase  "int:tolower"

# define the map file
RewriteMap   vhost      "txt:/www/conf/vhost.map"

# deal with aliases as above
RewriteCond  "%{REQUEST_URI}"               "!^/icons/"
RewriteCond  "%{REQUEST_URI}"               "!^/cgi-bin/"
RewriteCond  "${lowercase:%{SERVER_NAME}}"  "^(.+)$"
# this does the file-based remap
RewriteCond  "${vhost:%1}"                  "^(/.*)$"
RewriteRule  "^/(.*)$"                      "%1/docs/$1"

RewriteCond  "%{REQUEST_URI}"               "^/cgi-bin/"
RewriteCond  "${lowercase:%{SERVER_NAME}}"  "^(.+)$"
RewriteCond  "${vhost:%1}"                  "^(/.*)$"
RewriteRule  "^/cgi-bin/(.*)$"                      "%1/cgi-bin/$1" [H=cgi-script]

°¡´ÉÇÑ ¾ð¾î:  de  |  en  |  es  |  fr  |  ja  |  ko  |  tr  |  zh-cn