서 버
1. 개요
해당 모듈은 요청된 URL을 재작성하기 위한 룰기반(정규표현식 parse에 기반) 재작성 엔진입니다.
서버컨텍스트(httpd.conf) 또는 디렉토리 컨텍스트(.htaccess)에서 설정이 가능합니다.
Main Server에서의 설정은 Virtual Hosts에는 적용되지 않습니다.
Main Server 설정이 적용되기 위해서는 <VitrualHost> 섹션에 아래 내용을 추가해 주어야 합니다.
RewriteEngine On
RewriteOptions Inherit
2. 사용법
1) 해당 모듈을 로드(shared로 설치한 경우)
LoadModule rewrite_module modules/mod_rewrite.so
2) 설정지시자
RewriteBase URL-path
이지시자는 디렉토리 컨텍스트(.htaccess)에서 설정이 가능하고 base URL을 명백하게 설정하는 역할을 합니다.
사실 왜 필요한가에 대해서는 좀 의문이지만 원리에 대해 보면 아래와 같습니다.
아래와 같은 파일이 /abc/def/.htaccess 있다. 물론 서버설정에서 Alias /xyz /abc/def 로 처리되어 있습니다.
|
# # Remember: /abc/def is the physical path of /xyz, i.e., the server # has a 'Alias /xyz /abc/def' directive e.g. # RewriteEngine On # let the server know that we were reached via /xyz and not # via the physical path prefix /abc/def RewriteBase /xyz # now the rewriting rules RewriteRule ^oldstuff\.html$ newstuff.html |
처리 과정은 다음과 같습니다.
|
For Apache Hackers The following list gives detailed information about the internal processing steps: Request: /xyz/oldstuff.html Internal Processing: /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias) /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule) /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase) /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias) Result: /abc/def/newstuff.html |
위에서 보면 RewriteBase가 어떤 역할을 하는지 알수 있지요.
(RewriteRule이 처리된후 URL을 RewriteBase값대로 재작성하고 있습니다.)
실제 URL과 물리 파일 경로가 같지 않은 경우 설정할 필요가 있다고 합니다.
하지만 실제 있으나 없으나 겉으로는 구분이 되지 않고
처리되야할 과정이 더 늘었다 할수 있지만, 문서에 보면 올바른 처리과정이라고 나오네요.(?)
합당한 예제가 발견되면 댓글 달도록 하겠습니다.
참조사이트 : http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

감사합니다.