# Intercept status codes and redirect

**URL:** <https://community.f5.com/t/intercept-status-codes-and-redirect/54829>\
**Category:** Technical Forums\
**Tags:** irules, big-ip, application-delivery\
**Created:** [March 9, 2017, 4:49pm UTC](https://community.f5.com/t/intercept-status-codes-and-redirect/54829 "2017-03-09T16:49:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeTheFifth](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@JoeTheFifth](https://community.f5.com/u/JoeTheFifth)\
**Post date:** [March 9, 2017, 4:49pm UTC](https://community.f5.com/t/intercept-status-codes-and-redirect/54829/1 "2017-03-09T16:49:20Z")

</div>

I’m currently trying to find redirection mecanism based on status codes from server response. scenario is: Check for 2 two consecutive 401 status codes plus a 302 then a 200 + string in the 200 status code response. if these conditions are met =\> redirect to login page. Question 1: Is this possible with an irule? I did a simple 401 status check and I can see the status in the ltm log. Question 2: performance wise, will this bring the bigip to its knees with about 10.000 users a day? Question 3: what are my possibilities here? irule, access policy …??

Here is the simple rule:

when HTTP\_RESPONSE { if {[HTTP::status] eq “401”} { log local0. “401” }

}

If this is is possible then I will need help cooking an irule with variables and stuff 🙂

the logic would be: 2 401 + 302 + 200 with ‘accessdenied’ string The simple version is just check for the string accessdenied but I’d like to my the check more reliable with the preceding 2 401 and 302+200 codes.

---

<div class="post-metadata">

**Author:** ![Vijay\_E](https://avatars.discourse-cdn.com/v4/letter/v/4bbf92/32.png) [@Vijay\_E](https://community.f5.com/u/Vijay_E)\
**Post date:** [March 9, 2017, 8:47pm UTC](https://community.f5.com/t/intercept-status-codes-and-redirect/54829/2 "2017-03-09T20:47:38Z")

</div>

Your condition is not easy to track. You can have multiple HTTP requests passing through the F5 in random order for multiple connections. Making a decision based on a sequence of HTTP status code in a single connection seems a bit complicated. I would recommend trying to make a decision based on a specific value in the HTTP request instead of tracking multiple status codes.

You should be able to do something like [this](https://devcentral.f5.com/wiki/iRules.HTTP__status.ashx) for a simple redirect based on status code:

```tcl
when HTTP_RESPONSE {
  if { [HTTP::status] == 404 } {
    HTTP::redirect "http://www.example.com/not_found.html"
 }
}

```
