티스토리 뷰

WEB

mod_rewrite 예제)

CHOMAN 2017. 9. 13. 14:34


mod_rewrite 예제





도메인 요청 URL 에서 특정 가변적인 문자열 (아이디) 를 추출해서 서브도메인으로 만들고 나머지 요청은 그대로 유지



test.kensei.co.kr/webdev/takakocap/data/index.html (입력)


--> takakocap.kensei.co.kr/data/index.html (변환)

 





데이터 정의



test.kensei.co.kr --> 도메인 (값 고정)


/webdev --> 디렉토리 (값 고정)


/takakocap --> 디렉토리 (유저ID) (값 가변)


/data/index.html --> 유저 ID 디렉토리 이후 나머지 요청 (값 가변)

 




해결



RewriteEngine on

RewriteLog "/etc/httpd/logs/rewrite.log"

RewriteLogLevel 9

RewriteCond %{REQUEST_URI} /webdev/[a-zA-Z0-9]+/ [NC]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.com) [OR]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.net) [OR]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.org) [OR]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.biz) [OR]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.info) [OR]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.co.kr) [OR]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.or.kr) [OR]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.pe.kr) [OR]

RewriteCond %{SERVER_NAME} ([a-zA-Z0-9]+\.kr)

RewriteRule ^(.*)/webdev/([^/\.]+)/(.*)$ http://$2.%1/$3  [P,L]

RewriteRule ^(.*)/webdev/([^/\.]+)/(.*)$ https://$2.%1/$3  [P,L]

 




/etc/hosts



127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 takakocap.kensei.co.kr takakocap.kensei.com takakocap.kensei.net takakocap.kensei.or.kr

 



댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함