Forum Discussion
Using wildcards with classes
The redirection portion works perfectly. The problem is that the name portion has a lot of wildcard URIs and I can't figure out how to deal with them.
I'm posting a portion of a test data set, the current iRule, and the class commands from the config. I would really appreciate any help I can get.
testdatagroup_file
"/A1/" := "http://192.168.201.250/a.html",
"/A1/*" := "http://192.168.201.250/Athens/a.html",
"/B1/" := "http://192.168.201.250/b.html",
"/B1/*" := "http://192.168.201.250/Boston/b.html",
"/C1/" := "http://192.168.201.250/c.html",
"/C1/*" := "http://192.168.201.250/Chicago/c.html",
"/D1/" := "http://192.168.201.250/d.html",
"/D1/*" := "http://192.168.201.250/Dallas/d.html",
"/E1/" := "http://192.168.201.250/e.html",
"/E1/*" := "http://192.168.201.250/Elvira/e.html",
"/F1/" := "http://192.168.201.250/f.html",
"/F1/*" := "http://192.168.201.250/Franklin/f.html",
"/g/" := "http://192.168.201.250/g.html",
"/g/*" := "http://192.168.201.250/Gulf/g.html",
"/h/" := "http://192.168.201.250/h.html
"/h/*" := "http://192.168.201.250/Hanover/h.html
"/i/" := "http://192.168.201.250/i.html
"/i/*" := "http://192.168.201.250/indigo/i.html
class testdatagroup {
type string
filename "/config/testdatagroup_file"
separator ":="
}
redirectirule
Set debug to non-zero in the events you want to debug
debug levels: 0 - warnings only, 1 - testing, 2 - verbose
WARNING: verbose logging will be enormous with production dataset
when HTTP_REQUEST {
set debug 2
Set data variables
set HTTP_URI [HTTP::uri]
set HTTP_HOST [HTTP::host]
foreach element testdatagroup {
if {[string match -nocase $element $HTTP_URI]}{
log local0.notice "Element $element"
break
}
}
if { $debug > 0 } {log local0.notice "HTTP_URI set to [HTTP::uri] and HTTP_HOST set to [HTTP::host]."}
HTTP Redirect if correct
if { [string tolower ${HTTP_URI}] starts_with "/search?" and [URI::query ${HTTP_URI}] != ""} {
set my_query [URI::query ${HTTP_URI}]
if {$debug > 0} {log local0. "Redirecting ${HTTP_URI} to http://[HTTP::host]/Search/?${my_query}"}
HTTP::redirect "http://[HTTP::host]/Search/?${my_query}"
return
}
}
when HTTP_RESPONSE {
set dgname "testdatagroup"
if { $debug > 0 } {log local0.notice "Data Group: $dgname"}
log local0.notice "URIPATH [URI::path $HTTP_URI]"
set DG_name [class search -name testdatagroup contains $HTTP_URI ]
log local0.notice "DG_name: $DG_name"
if { [string match "\*" "${DG_name}"]} {
set name [class match -name $HTTP_URI starts_with testdatagroup ]
set value [class match -value $HTTP_URI contains testdatagroup]
if { $debug > 0 } {log local0.notice "Name Value: $name"}
} else {
set name [class match -name $HTTP_URI starts_with testdatagroup ]
set value [class match -value $HTTP_URI contains testdatagroup]
if { $debug > 0 } {log local0.notice "Name Value: $name"}
}
set newmap [class search -value testdatagroup equals [class match -name $HTTP_URI starts_with testdatagroup ]]
if { $debug > 0 } {log local0.notice "Redirect: $newmap"}
HTTP::respond 301 Location "$newmap"
}
Once again, I would appreciate any help at all.
Cosby
- hooleylistCirrostratusHi Cosby,
- Cosby_17532NimbostratusAaron,
- hooleylistCirrostratusYep, so for any exact match like /petfriendshhop/, you'd add it to the exact match datagroup and use the equals operator. For a URI token that has a * on the end, you'd add it without the * to a "starts_with" datagroup and use the "starts_with" operator on class match. Similarly, if you had ends_with checks you wanted to do, you could use the same logic as starts_with. If you need to support wildcards in the middle of strings in the datagroup, you'd need to retrieve the entire datagroup as a TCL list using 'class get' and then loop through the entries one by one using 'string match'.
- Naman_65674NimbostratusHi Hoolio,
- webops_97953Nimbostratus
+1 this feature would be great! and also supporting wildcards when creating data-groups with tmsh
- ArieAltostratus
You can work around the limitation by moving the match indicator (wildcard vs. exact match) to the value and using a separator.
In other words,
"/g/*" := "http://192.168.201.250/Gulf/g.html"
becomes
"/g/" := "*;http://192.168.201.250/Gulf/g.html"
and
"/E1/" := "http://192.168.201.250/e.html"
becomes
"/E1/" := "=;http://192.168.201.250/e.html"
This way you can build logic into your code to handle the two scenarios. I can elaborate if necessary.
- webops_97953Nimbostratus
nice workaround, thanks you!
Recent Discussions
Related Content
* 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