# irule to return status code

**URL:** <https://community.f5.com/t/irule-to-return-status-code/14039>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [January 23, 2009, 3:59pm UTC](https://community.f5.com/t/irule-to-return-status-code/14039 "2009-01-23T15:59:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DarkSideOfTheQ](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DarkSideOfTheQ](https://community.f5.com/u/DarkSideOfTheQ)\
**Post date:** [January 23, 2009, 3:59pm UTC](https://community.f5.com/t/irule-to-return-status-code/14039/1 "2009-01-23T15:59:49Z")

</div>

I’m still learning here, so bear with me. I am trying to write an irule that will catch requests trying to pull content from a specific set of hosts (ex. [myserver1.domain.com](http://myserver1.domain.com), [myserver2.domain.com](http://myserver2.domain.com), [myserver3.domain.com](http://myserver3.domain.com)) and return a 200 status code.

Here is what I have put together, but I’m not sure what I have wrong.

when HTTP\_REQUEST {

if { [HTTP::uri]} contains ‘myserver’ [HTTP::respond 200]

}

TIA,

DarkSide

---

<div class="post-metadata">

**Author:** ![dennypayne](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/dennypayne/32/1364_2.png) [@dennypayne](https://community.f5.com/u/dennypayne)\
**Post date:** [January 23, 2009, 5:00pm UTC](https://community.f5.com/t/irule-to-return-status-code/14039/2 "2009-01-23T17:00:04Z")

</div>

Hi,

You’d want to use HTTP::host rather than HTTP::uri in this case, since myserver is part of the hostname and not the uri. This also assumes that those hostnames all point to the same virtual server address in DNS. Is that what you are looking for?

Also, just responding with a 200 and no content probably won’t yield much, but maybe that’s what you want.

Denny

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [January 23, 2009, 5:08pm UTC](https://community.f5.com/t/irule-to-return-status-code/14039/3 "2009-01-23T17:08:16Z")

</div>

Denny’s right, so what you’d want instead is something like:

```tcl
when HTTP_REQUEST {  
    switch -glob [HTTP::host] {  
      "*myserver1.domain.com" -  
      "*myserver2.domain.com" -  
      "*myserver3.domain.com" {  
        HTTP::respond 200 content "Response from LTM iRule"  
      }  
    }  
  }

```

Of course you can get a lot more detailed in the response you want to send, too. Take a look at the HTTP::respond wiki page for some examples - [Click here](http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__respond.html)

HTH,

Colin

---

<div class="post-metadata">

**Author:** ![DarkSideOfTheQ](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DarkSideOfTheQ](https://community.f5.com/u/DarkSideOfTheQ)\
**Post date:** [January 23, 2009, 5:29pm UTC](https://community.f5.com/t/irule-to-return-status-code/14039/4 "2009-01-23T17:29:08Z")

</div>

You guys are awesome, thanks a bunch. Course, now I’ve realized I was totally off-base with what I had put together. Is there a good link (maybe the wiki one you provided Colin) that will help me learn the irule syntax that is available in these devices? I know it’s TCL based (which I don’t know and must learn now), but read that not all TCL commands are implemented.

Colin - Yes, they are all pointing to the same vip, which was serving up some sort of content. The app owner is decommissioning the app and wanted the LB to simply return a 200 status to any 3rd parties were still pointing to it.

Thanks Again,

-DarkSide

---

<div class="post-metadata">

**Author:** ![DarkSideOfTheQ](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DarkSideOfTheQ](https://community.f5.com/u/DarkSideOfTheQ)\
**Post date:** [January 23, 2009, 5:40pm UTC](https://community.f5.com/t/irule-to-return-status-code/14039/5 "2009-01-23T17:40:14Z")

</div>

nm…if i had bothered to look at the “Spotlight Wikis” links, I would have found what I seek.

Again…Thanks!
