Forum Discussion
Rusty_Hale_8009
Nimbostratus
Apr 05, 2005iRule conversion from 4.X to V9
I have made an attempt to convert an iRule to V9. Could someone please check my syntax? I would really appreciate it. Thanks.
if { [HTTP::host]
rule Image_Rule {
...
Apr 05, 2005
citizen_elah,
There's a few syntax errors (if's use curly braces, and else,elseif should be on the same line as closing curly brace) in there but by cleaning those your solution should work. Here are 3 possible rules (assuming the uri actually "ends with" the image type - otherwise use the "contains operator").
Here's a modified version of your solution
when HTTP_REQUEST {
if { [HTTP::host] equals "www.mydomain.com" } {
if { [HTTP::uri] ends_with ".jpg" } {
use pool Image_Svr_80
log "JPG file requested by [IP::client_addr]"
} elseif { [HTTP::uri] ends_with ".gif" } {
use pool Image_Svr_80
log "GIF file requested by [IP::client_addr]"
} else {
use pool Main_Svr_80
log "Default LB Method for [IP::client_addr]"
}
}
}
If you want to shorten this up without all the detailed logging for each image type, you could also do the following
when HTTP_REQUEST {
if { [HTTP::host] equals "www.mydomain.com" and \
[HTTP::uri] ends_with ".jpg" or \
[HTTP::uri] ends_with ".gif" } {
use pool Image_Svr_80
log "Image file requested by [IP::client_addr]"
} else {
use pool Main_Svr_80
log "Default LB Method for [IP::client_addr]"
}
}
If the group of image types increase, you might want to use a data group to store the image types to simplifly the script
class images {
".gif"
".jpg"
}
when HTTP_REQUEST {
if { [HTTP::host] equals "www.mydomain.com" and \
[matchclass [HTTP::uri] ends_with $::images] } {
use pool Image_Svr_80
log "Image file requested by [IP::client_addr]"
} else {
use pool Main_Svr_80
log "Default LB Method for [IP::client_addr]"
}
}
*Note that the "class image{...}" is not included in the rule but where declared externally as a data group list.
** Also note that the log lines are optional and can be included for trouble shooting.
-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