Apache mod_rewrite

<시나리오>

- 클라이언트가 요청시 쿼리 value 에 항상 쓰레기 값이 붙어서 넘어옴

- 클리이언트 측 프로그램은 변경불가 Never and Ever~~. 어쩔 수 없이 서버쪽에서 수정해야 함 OTL....

 

<httpd.conf>

====================================================================================

~~~~

RewriteEngine On

RewriteMap division-handle txt:conf/rewriteMap.txt

# 아래꺼 잘됨
#RewriteRule /shit/([0-9]+) /rewrite.php?id=$1

# /serviceName/wapGateway?clientID=ver0.1
&phoneNo=01057401039&pgmid=HW12000
&bookType=N&division=100\t&pageNum=2&maxRowNo=10
# 위의 URL을
# /serviceName/wapGateway?clientID=ver0.1
&phoneNo=01057401039&pgmid=HW12000
&bookType=N&division=100&pageNum=2&maxRowNo=10
# 이렇게 매치시켜야 함

# fail - 아래와 같은 방식은 안됨
#RewriteRule /serviceName/wapGateway?clientID=ver(([0-9]+)|([0-9]*"."[0-9]+))
&phoneNo=([0-9]+)&pgmid=HW12000&bookType=([A-Z])&division=([0-9]+)\t
&pageNum=([0-9]+)&maxRowNo=([0-9]+)$ /error.php

# fail
#RewriteRule /serviceName/wapGateway?clientID=([0-9]+) /error.php

# success
#RewriteRule /serviceName/wapGateway /error.php

# http://localhost/serviceName/wapGateway?clientID=\t&phoneNo=01057401039
# success
#RewriteCond %{QUERY_STRING} ^clientID=\\t&phoneNo=01057401039$ [NC]

# success
RewriteCond %{QUERY_STRING} ^clientID=ver0.1&phoneNo=([0-9]+)
&pgmid=HW12000&bookType=([A-Z])&division=([0-9]+)\\t
&pageNum=([0-9]+)&maxRowNo=([0-9]+)$

#success
#RewriteRule ^(.*)$ /error.php

#success but OUT JSP SOURCE!!!
#RewriteRule ^(.*)$ /debug.jsp

#success
RewriteRule ^(.*)$ http://localhost/debug.jsp
#RewriteRule ^(.*)$ http://localhost/debug.jsp?clientID=ver0.1
&phoneNo=$1&pgmid=HW12000&bookType=$2
&division=$3&pageNum=$4&maxRowNo=$5

#success
#RewriteRule ^(.*)$ http://localhost:9090/debug.jsp


#RewriteRule ^gate.php?id=([0-9]+)$ /rewrite.php?id=$1
#RewriteRule ^gate.php$ /error.php

RewriteLog      "C:/APM_Setup/Server/Apache/logs/rewrite.log"
RewriteLogLevel 9

====================================================================================

<rewriteMap.txt>

##
##  map.txt -- rewriting map
##

100\\t 100   #
200\\t 200   #
~~~
~~~

====================================================================================

<참조 URL>

* mod_rewrite :
- http://www.sitepoint.com/article/guide-url-rewriting
- http://www.llstudios.net/directory/13-1
- http://www.llstudios.net/directory/4-1
- http://www.tech-faq.com/lang/ko/web-design-tutorials.shtml
- http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

* 정규표현식 :
http://kldp.org/HOWTO/html/Adv-Bash-Scr-HOWTO/x10468.html