Forum Discussion
Kev_Pearce_1070
Nimbostratus
Oct 04, 2006Lookup a lookup...
Hi all,
I'm trying to make my life easier by having a single iRule that lookups the name of a data set from another data set and then do a matchclass against this returned name. Then do this for each row in the lookup data set... okay some code might help here, something like:
class lookup_redirects {
"$::domainlist_1 http://www.whatever.com/redirect-to-here"
"$::domainlist_2 http://www.whatever.com/redirect-to-there"
}
class domainlist_1 {
"www.whatever123.co.uk"
"www.whatever123.com"
}
class domainlist_2 {
"www.whateverelse.co.uk"
"www.whateverelse.com"
}
when HTTP_REQUEST {
foreach row $::lookup_redirects {
set domainlist [getfield $row " " 1]
set rdurl [getfield $row " " 2]
if { [matchclass [HTTP::host] contains $domainlist ] } {
log local0. "Request to: [HTTP::host] redirected: to $rdurl"
HTTP::redirect $rdurl
return
}
}
}
I'm not sure if the 'set dl'... should be an 'array set dl'... but neither work....
Errors something about even number of elements...???
TCL is not my first language... any ideas???
This would make my redirect lsts so much easier!!!
Cheers very much all
Kev/.
3 Replies
- hoolio
Cirrostratus
I think using findclass with one class (datagroup) might be an easier option.
Here is an example: (Click here)
You can also check the iRule wiki for more details on findclass.
Aaron - Kev_Pearce_1070
Nimbostratus
Hi,
I have nearly 100 redirects to include. Some full site, some path and some specific files. Many of them apply to the same lists of domain names so i was hoping to beable to reuse these lists by having multiple data sets.
I'll keep working on it...
Kev/. - Try enclosing the lookup_redirects entries in curly braces, not quotes. By using quotes, the interpreter is expanding the list contents so the resulting list is this:
"www.whatever123.co.uk www.whatever123.com http://www.whatever.com/redirect-to-here"
...
In your code domainlist would be www.whatever123.co.uk and rdurl would be www.whatever123.com, not the url that you were expecting.
When using braces the variables are not expanded but stored by reference.class lookup_redirects { {$::domainlist_1 http://www.whatever.com/redirect-to-here} {$::domainlist_2 http://www.whatever.com/redirect-to-there} }
I believe this will work, let me know if not.
If all else fails, use log statements everywhere. If you would have logged the value for $row on each iteration of the foreach loop you would have seen that it wasn't what you expected. Also log all variables. This would have told you something was up right away.
-Joe
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