Forum Discussion
Error page iRules
I have recently been tasked with maintaining an F5 implementation and i am looking into how to develop iRules for error pages (maintenance, 404 etc).
My issue is that instead of having the html within the iRule itself i want to have the page written in an iFile that i then reference within each iRule.
I can get this to work (to an extent!) however i cannot get any images to show. Do i have to use data group lists for this?
Please bear in mind that i am a bit of a novice so any replies will need to be easy to understand!
Thanks
9 Replies
- nitass
Employee
I can get this to work (to an extent!) however i cannot get any images to show. Do i have to use data group lists for this?no, data group is not needed. you are using HTTP::respond and ifile similar to the article below, aren't you? can you post the irule?
v11.1–External File Access from iRules via iFiles by Jason Rahm
https://devcentral.f5.com/tech-tips/articles/v111-ndashexternal-file-access-from-irules-via-ifiles - Kevin_Stewart
Employee
Take a look at this recent thread:
https://devcentral.f5.com/community/group/aft/2166746/asg/502276717
Ideally you want to include the Content-Type header in the HTTP::respond command that pulls the ifile for display.
ex.
HTTP::respond 200 content [ifile get myuflheaderborder.jpg] "Content-Type" "image/jpeg"
Otherwise you use the same process for uploading images to ifiles as you do for text/html files. - AliMack85_11443
Nimbostratus
Thanks for the speedy replies!
I just wrote this very quickly to try it out so its not fit for purpose yet:
when HTTP_REQUEST {
if {[HTTP::uri] eq "/"}{
{
HTTP::respond 200 content [ifile get errorpage.txt] "Content-Type" "text/html"
}
"/image01_en.png" {
HTTP::respond 200 content [ifile get image01_en.png] "Content-Type" "image/png"
}
When i try and save this irule it brings back "undefined procedure" errors.
I am just starting out with this stuff so there are probably some glaring mistakes here!
}
} - Kevin_Stewart
Employee
iFile was introduced in 11.1.0. Which TMOS version are you running? - What_Lies_Bene1
Cirrostratus
Lots of mistakes, here's my corrections plus switching from if to switch;when HTTP_REQUEST { switch { [string tolower [HTTP::uri]] } { "/" { HTTP::respond 200 content [ifile get errorpage.txt] "Content-Type" "text/html" } "/image01_en.png" { HTTP::respond 200 content [ifile get image01_en.png] "Content-Type" "image/png" } } } - AliMack85_11443
Nimbostratus
The version we are using is 11.3.0 - What_Lies_Bene1
Cirrostratus
Even more corrections, no need for file extensions, no quotes around Content-Type;when HTTP_REQUEST { switch { [string tolower [HTTP::uri]] } { "/" { HTTP::respond 200 content [ifile get "errorpage"] Content-Type "text/html" } "/image01_en.png" { HTTP::respond 200 content [ifile get "image01_en"] Content-Type "image/png" } } } - AliMack85_11443
Nimbostratus
Fantastic, got it to work!
I only had to make one amendment to your last post:
switch [string tolower [HTTP::uri]] {
I took out the curly brackets around the [string to lower [HTTP::uri]]
Thanks for all your help! - What_Lies_Bene1
Cirrostratus
Great, you're welcome.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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