# 404 Handler

**URL:** <https://community.f5.com/t/404-handler/14407>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [August 2, 2010, 4:02am UTC](https://community.f5.com/t/404-handler/14407 "2010-08-02T04:02:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eireann78\_19953](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@Eireann78\_19953](https://community.f5.com/u/Eireann78_19953)\
**Post date:** [August 2, 2010, 4:02am UTC](https://community.f5.com/t/404-handler/14407/1 "2010-08-02T04:02:32Z")

</div>

Hi, I need an irule which catches 404s returned from a server pool and re-directs to a friendly page. when HTTP\_RESPONSE { if { [HTTP::status] == 404} { HTTP::respond “[http://www](http://www)..test.com/pagenotfound” } } My problem is the pagenotfound returns a 404 status code so it has created a loop. Any advice on the best way to proceed I have done some searching but haven’t found an irule which matches what I need to do. Cheers.

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [August 2, 2010, 8:56pm UTC](https://community.f5.com/t/404-handler/14407/2 "2010-08-02T20:56:51Z")

</div>

As Chris said, the 404 handler page shouldn’t return a 404 itself. Though if this is something you can to implement and you can’t change the status, you could save the URI in HTTP\_REQUEST and then not redirect to the 404 page if the request is for it already.

```tcl
when HTTP_REQUEST {
   set uri [HTTP::uri]
}
when HTTP_RESPONSE {
   if { [HTTP::status] == 404 and $uri ne "/404.html"} {
      HTTP::redirect "http://www.example.com/404.html"
   }
}

```

Aaron
