Convert 404s to Blank 200s

Problem this snippet solves:

An iRule to convert an HTTP 404 response to a blank 200 response. HTTP 404 responses cannot be cached and will always hit your back end infrastructure. If you are using a proxy/cache for your web application, you can convert the HTTP 404 response to a blank 200 response that can be cached. This can be useful for reducing the load on your back end if you have a web site which is always under construction. It can also help mitigate one type of denial of service attack.

Code :

# iRule to replicate no 404s
when HTTP_REQUEST {
  # Don't allow data to be chunked
  if { [HTTP::version] eq "1.1" } {
    if { [HTTP::header is_keepalive] } {
      HTTP::header replace "Connection" "Keep-Alive"
    }
     HTTP::version "1.0"
  }
}
when HTTP_RESPONSE {
   # grab response of a 404
   if {[HTTP::status] == 404}{
      HTTP::collect [HTTP::header Content-Length]
   }
}

when HTTP_RESPONSE_DATA {
   # change response to 200 and send
   HTTP::respond 200 content [HTTP::payload]
}
Published Mar 17, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment