Forum Discussion
Leslie_South_55
Nimbostratus
Oct 19, 2007findclass AND external class AND wildcards
I am using an external class file to do URI redirects, when using speciffic URI matching it works fine: when HTTP_REQUEST {
log local0. "Uri is [HTTP::uri]"
set NewURI [findclass [HTTP::uri]...
hoolio
Cirrostratus
Oct 23, 2007Sorry, I should have included more comments...
The format for foreach is:
foreach one_line $::class_or_array {
do something
}The $::class_or_array must already exist. A single line of the class or array is assigned to the variable called one_line.
The getfield commands return a specific field from a line. The two double quotes indicate that a space is the delineator between the fields. So 1 is the first field. 2 is for the second field.
For an example class:
class string_class {
"111 aaa"
"222 bbb"
"333 ccc"
}The following rule:
when RULE_INIT {
foreach line $::string_class {
log local0. "One Line: \$line: $line"
log local0. "\[getfield \$line \" \" 1\]: [getfield $line " " 1]"
log local0. "\[getfield \$line \" \" 2\]: [getfield $line " " 2]"
}
}Will return:
One Line: $line: 111 aaa
[getfield $line " " 1]: 111
[getfield $line " " 2]: aaa
One Line: $line: 222 bbb
[getfield $line " " 1]: 222
[getfield $line " " 2]: bbb
One Line: $line: 333 ccc
[getfield $line " " 1]: 333
[getfield $line " " 2]: cccI should have included a return command to exit the foreach loop once a match is found. Also, you're redirecting to just a URI, without a host. The example below redirects to the same Host that the client requested. I've added some more logging to help troubleshoot the issue. Can you try this and reply with the results/logs?
when HTTP_REQUEST {
log local0. "URI is [HTTP::uri]"
foreach line $::wwwredirects {
log local0. "Current line from the class: $line"
if {[HTTP::path] starts_with [getfield $line " " 1]}{
log local0. "Matched: [HTTP::path] to: [getfield $line " " 1]"
HTTP::redirect "http://[HTTP::host][getfield $line " " 2]"
log local0. "redirecting to http://[HTTP::host][getfield $line " " 2]"
Break from the foreach loop once a match is found so no further checks/redirects are done
break
}
}
}Thanks,
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
