Posted By citizen_elah on 05/31/2007 6:23 AM
I couldn't quite infer whether those mappings are static or dynamically generated, but if they are static, you can easily create a class for that:
class myURImappings {
"abc xyz"
"bcd wxy"
"cde vwx"
"def uvw"
}
Then your rule is quite simple:
when HTTP_REQUEST {
if { [matchclass [string tolower [HTTP::uri]] starts_with $::myURImappings] } {
HTTP::respond 301 Location "http://www.mydomain.com/[findclass [string tolower[HTTP::uri] $::myURImappings " "]"
}
}
That won't quite work because the value of HTTP::uri will always start with a slash. Also, your findclass call is assuming that the URI
equals the value in the class, but the originally supplied code used the
contains operator.
We don't have measurements for class lists of 10000+ entries, but you'll have to expect that it will have a performance impact (you can't get 10000 string comparisons for free).
If you can supply some real examples of what you are trying to map from/to there might be a way to use some tricks to limit the number of mappings needed. For instance, if you need to map:
/aaa/foo -> /ZZZ/foo
/aaa/bar -> /ZZZ/bar
...
Then you can do some string splitting and just extract the first element of the URI and look that up, then dynamically build the redirect/respond retaining the original trailing section of the URI. But without examples/requirements I don't know if that will work for you.
-Joe