Forum Discussion

AliMack85_11443's avatar
AliMack85_11443
Icon for Nimbostratus rankNimbostratus
Apr 29, 2013

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

 

  • 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
  • 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.
  • 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!

     

    }

     

    }
  • 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" }
     } 
    }
    
  • 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" }
     } 
    }
    
  • 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!