Wil_Schultz_101
Dec 13, 2007Nimbostratus
Fun with regexp...
Just ran into a fun little problem, thought I would share and maybe ask if there is a better/more efficient way to do this.
Problem:
URI that are either 4 or 5 digits in length, and may or may not end with a trailing slash, go to a certain place under a hidden URI
Exception:
URI that the first 4 digits are 1900-2099 and may (or may not) have another number afterwards, and URI that are more then 5 numerals in length are also exceptions and go to another pool.
Solution:
when HTTP_REQUEST {
set uri1 null
set uri2 null
regexp {^/(19[0-9][0-9]|20[0-9][0-9])[0-9]?} [HTTP::uri] uri1
regexp {^/[0-9]{4}[0-9]?/?$} [HTTP::uri] uri2
if {!($uri1 == "null") } {
log "... 1 $uri1"
pool pool1
return 0
}
if {!($uri2 == "null") } {
regexp {[0-9]*/?$} [HTTP::uri] uri3
log "... 2 $uri2 $uri3"
HTTP::uri "http://www.domain.com/cgi-bin/dosomething.cgi?url=$uri3"
pool pool2
return 0
}
}