Filter by:
  • Solution
  • Technology

answers

irule 404 page

Updated 1/18/2013 • Originally posted on 18-Jan-2013 by craig_lee10 -2

Hi

I am wondering if someone can point me in the right direction. Basically the below works fine when I try and go to a directory that doesn’t exists

 

when HTTP_RESPONSE {
    if { [HTTP::status] == 404 } {
        HTTP::respond 200 content [ifile get "index"]
}
}

The issue I have is that the file index is an html file which references images etc which don’t get displayed the when the page is severed.  I have tried using ifles to resolve this but I think my syntax is wrong; could someone give me a suggestion on what I need to do?

Thanks

 

Craig

0
Rate this Question

Answers to this Question

6 Answers:

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Updated 18-Jan-2013 • Originally posted on 18-Jan-2013 by What Lies Beneath 6427
This post should give you almost everything you need: https://devcentral.f5.com/community/group/aft/2165545/asg/50

However, you'll need to add some logic to ensure requests you don't want handled by this are just passed along. I'd suggest you add some unique path for the images in the index.html file that the 'normal' application would never use, for example: /404/404/image1.jpg. Then you can just do an if [HTTP::uri]] starts_with "/404/404" in a HTTP_REQUEST event; if it matches, you'll serve the iFile, if not things just work as normal.
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Updated 18-Jan-2013 • Originally posted on 18-Jan-2013 by What Lies Beneath 6427
A quick example;

when HTTP_REQUEST {
 if { [HTTP::uri] starts_with "/404/404" } {
 switch -glob [string tolower[HTTP::uri]] {
  "*/favicon.ico" { HTTP::respond 200 content [ifile get favicon_ico] }
  "*/reset.css" { HTTP::respond 200 content [ifile get reset_css] }
  }
 }
}
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Updated 18-Jan-2013 • Originally posted on 18-Jan-2013 by craig_lee10 -2
that makes sense now, ill give that a go and let you know what happens, many thanks Steve for your time.
Craig
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Updated 18-Jan-2013 • Originally posted on 18-Jan-2013 by What Lies Beneath 6427
You're welcome. Post back if you need to.
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Updated 18-Jan-2013 • Originally posted on 18-Jan-2013 by nitass 12650
e.g.

[root@ve11a:Active:Changes Pending] config # tmsh
root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos)# list ltm virtual bar
ltm virtual bar {
    destination 172.28.20.14:80
    ip-protocol tcp
    mask 255.255.255.255
    pool foo
    profiles {
        http { }
        tcp { }
    }
    rules {
        myrule
    }
    source 0.0.0.0/0
    source-address-translation {
        type automap
    }
    vlans-disabled
}
root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos)# list ltm pool foo
ltm pool foo {
    members {
        200.200.200.101:80 {
            address 200.200.200.101
        }
    }
}
root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos)# list ltm rule myrule
ltm rule myrule {
    when HTTP_RESPONSE {
  if { [HTTP::status] == 404 } {
    HTTP::respond 200 content [ifile get maint_html_ifile] noserver "Content-Type" "text/html"
  }
}
when HTTP_REQUEST {
  switch [HTTP::uri] {
    "/f5.gif" { HTTP::respond 200 content [ifile get f5_gif_ifile] noserver "Content-Type" "image/gif" }
  }
}
}

# original response from pool

[root@ve11a:Active:Changes Pending] config # curl -I http://200.200.200.101/something
HTTP/1.1 404 Not Found
Date: Sat, 19 Jan 2013 06:50:00 GMT
Server: Apache/2.2.3 (CentOS)
Content-Type: text/html; charset=iso-8859-1

# rewritten response from bigip

[root@ve11a:Active:Changes Pending] config # curl -i http://172.28.20.14/something
HTTP/1.0 200 OK
Content-Type: text/html
Connection: Keep-Alive
Content-Length: 97

<html>
<head></head>
<body>
This is maintenance page.
<br><br><img src="f5.gif">
</body>
</html>

[root@ve11a:Active:Changes Pending] config # curl -I http://172.28.20.14/f5.gif
HTTP/1.0 200 OK
Content-Type: image/gif
Connection: Keep-Alive
Content-Length: 3994

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Updated 23-Jan-2013 • Originally posted on 23-Jan-2013 by craig_lee10 -2
Thanks for your help guys this is what I used in the end

when HTTP_REQUEST {
log local0. "\HTTP::host\]\[HTTP::uri\]: [string tolower [HTTP::host]][string tolower [HTTP::uri]]"
switch -glob [string tolower [HTTP::uri]] {


"*404/404/css/baselogin.css" {HTTP::respond 200 content [ifile get baselogin] "Content-Type" "text/css"}

"*404/404/images/icon_alert.gif" {HTTP::respond 200 content [ifile get icon_alert] "Content-Type" "image/gif"}

"*404/404/images/logo_percep_sm.gif" {HTTP::respond 200 content [ifile get percep_sm] "Content-Type" "image/gif"}

"*404/404/images/bkg_loginbody.gif" {HTTP::respond 200 content [ifile get bkg_loginbody]"Content-Type" "image/gif" }

"*404/404/images/bkg_loginbottom.gif" {HTTP::respond 200 content [ifile get bkg_loginbottom]"Content-Type" "image/gif" }

"*404/404/images/bkg_logintop.gif" {HTTP::respond 200 content [ifile get bkg_logintop]"Content-Type" "image/gif" }

"*404/404/images/bkg_logintop.gif" {HTTP::respond 200 content [ifile get bkg_splashbody]"Content-Type" "image/gif" }


}
}


when HTTP_RESPONSE {


if { [HTTP::status] == 404 } {
HTTP::respond 200 content [ifile get "main_index"] noserver "Content-Type" "text/html" }
}
;