Forum Discussion
Need help with iRule using iFiles
Hey all,
I have an iRule that calles iFiles for a local maintenance page but only seems to work at the root of the URL.
ex. www.example.com/ -> works, renders html text and graphic. www.example.com/anythingelse/ -> fails, only renders html text and no graphics.
when HTTP_REQUEST priority 10 {
switch [HTTP::uri] {
"/down.jpg" {
HTTP::respond 200 content [ifile get down.jpg] "Content-Type" "image/png" "Connection" "Close"
event HTTP_REQUEST disable
}
"/poweredby.gif" {
HTTP::respond 200 content [ifile get poweredby.gif] "Content-Type" "text/css" "Connection" "Close"
event HTTP_REQUEST disable
}
default {
if { ( [HTTP::uri] starts_with "/" ) } {
HTTP::respond 200 content [ifile get down.html] "Content-Type" "text/html" "Connection" "Close"
event HTTP_REQUEST disable
}
}
}
}
I'm guessing you are trying to match the file no matter the path. If that's the case you need a glob added to the switch and "*" added to your jpg and gif uris:
when HTTP_REQUEST priority 10 { switch -glob [HTTP::uri] { "*/down.jpg" { HTTP::respond 200 content [ifile get down.jpg] "Content-Type" "image/png" "Connection" "Close" event HTTP_REQUEST disable } "*/poweredby.gif" { HTTP::respond 200 content [ifile get poweredby.gif] "Content-Type" "text/css" "Connection" "Close" event HTTP_REQUEST disable } default { if { ( [HTTP::uri] starts_with "/" ) } { HTTP::respond 200 content [ifile get down.html] "Content-Type" "text/html" "Connection" "Close" event HTTP_REQUEST disable } } } }
- Brad_ParkerCirrus
I'm guessing you are trying to match the file no matter the path. If that's the case you need a glob added to the switch and "*" added to your jpg and gif uris:
when HTTP_REQUEST priority 10 { switch -glob [HTTP::uri] { "*/down.jpg" { HTTP::respond 200 content [ifile get down.jpg] "Content-Type" "image/png" "Connection" "Close" event HTTP_REQUEST disable } "*/poweredby.gif" { HTTP::respond 200 content [ifile get poweredby.gif] "Content-Type" "text/css" "Connection" "Close" event HTTP_REQUEST disable } default { if { ( [HTTP::uri] starts_with "/" ) } { HTTP::respond 200 content [ifile get down.html] "Content-Type" "text/html" "Connection" "Close" event HTTP_REQUEST disable } } } }
- joxonu_175315NimbostratusThanks for the quick response and solution. Really appreciate it!
- Brad_ParkerCirrusAre you getting the expected result?
- joxonu_175315NimbostratusSorry for the delayed response. Yes it is working as expected with the "glob" match. Thanks again for the timely response and fix!
- Brad_Parker_139Nacreous
I'm guessing you are trying to match the file no matter the path. If that's the case you need a glob added to the switch and "*" added to your jpg and gif uris:
when HTTP_REQUEST priority 10 { switch -glob [HTTP::uri] { "*/down.jpg" { HTTP::respond 200 content [ifile get down.jpg] "Content-Type" "image/png" "Connection" "Close" event HTTP_REQUEST disable } "*/poweredby.gif" { HTTP::respond 200 content [ifile get poweredby.gif] "Content-Type" "text/css" "Connection" "Close" event HTTP_REQUEST disable } default { if { ( [HTTP::uri] starts_with "/" ) } { HTTP::respond 200 content [ifile get down.html] "Content-Type" "text/html" "Connection" "Close" event HTTP_REQUEST disable } } } }
- joxonu_175315NimbostratusThanks for the quick response and solution. Really appreciate it!
- Brad_Parker_139NacreousAre you getting the expected result?
- joxonu_175315NimbostratusSorry for the delayed response. Yes it is working as expected with the "glob" match. Thanks again for the timely response and fix!
- IheartF5_45022Nacreous
Have you created the iFile as both a sys file and an LTM file ie.
tmsh create sys file ifile "down_jpg" source-path file:/var/class/down.jpg tmsh create ltm ifile "down_jpg" file-name "down_jpg"
You need to in order to reference it from an iRule. In addition I've always removed '.' from iFile names (but not sure if this has been due to madness on my part or an actual issue).
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