# action if http::header host exists

**URL:** <https://community.f5.com/t/action-if-http-header-host-exists/38915>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [February 5, 2008, 4:32pm UTC](https://community.f5.com/t/action-if-http-header-host-exists/38915 "2008-02-05T16:32:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baqar\_Husain\_81](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@Baqar\_Husain\_81](https://community.f5.com/u/Baqar_Husain_81)\
**Post date:** [February 5, 2008, 4:32pm UTC](https://community.f5.com/t/action-if-http-header-host-exists/38915/1 "2008-02-05T16:32:12Z")

</div>

Simple enough question, and I’m drawing a blank and can’t find anything relevant in the wiki or the forums:

Just looking for the correct syntax ..

if exists Host then replace HTTP::host with [my.xyz.com](http://my.xyz.com)

else

insert HTTP::header Host [your.xyz.com](http://your.xyz.com)

I’m converting HTTP/1.0 requests to HTTP/1.1 … that part is working fine, but I want the LTM to insert an HTTP HOST entry should the original 1.0 request not have it.

Thanks

---

<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:** [February 5, 2008, 5:08pm UTC](https://community.f5.com/t/action-if-http-header-host-exists/38915/2 "2008-02-05T17:08:57Z")

</div>

Something like this?

```tcl
when HTTP_REQUEST {
   if {[string length [HTTP::header value Host]]}{
      HTTP::header replace Host my.xyz.com
   } else {
      HTTP::header replace Host your.xyz.com
   }
}

```

Aaron

---

<div class="post-metadata">

**Author:** ![Deb\_Allen\_18](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Deb\_Allen\_18](https://community.f5.com/u/Deb_Allen_18)\
**Post date:** [February 6, 2008, 12:34am UTC](https://community.f5.com/t/action-if-http-header-host-exists/38915/3 "2008-02-06T00:34:01Z")

</div>

Why not just use the “HTTP::header exists” command?

```tcl
when HTTP_REQUEST {
   if {[HTTP::header exists Host]}{
      HTTP::header replace Host my.xyz.com
   } else {
      HTTP::header replace Host your.xyz.com
   }
}

```

???

/deb

---

<div class="post-metadata">

**Author:** ![Baqar\_Husain\_81](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@Baqar\_Husain\_81](https://community.f5.com/u/Baqar_Husain_81)\
**Post date:** [February 6, 2008, 4:35pm UTC](https://community.f5.com/t/action-if-http-header-host-exists/38915/4 "2008-02-06T16:35:20Z")

</div>

Thank you both.

---

<div class="post-metadata">

**Author:** ![Baqar\_Husain\_81](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@Baqar\_Husain\_81](https://community.f5.com/u/Baqar_Husain_81)\
**Post date:** [February 6, 2008, 4:37pm UTC](https://community.f5.com/t/action-if-http-header-host-exists/38915/5 "2008-02-06T16:37:27Z")

</div>

would the HTTP::header replace Host [your.xyz.com](http://your.xyz.com) work if the Host statement doesn’t exist?

---

<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:** [February 7, 2008, 11:03am UTC](https://community.f5.com/t/action-if-http-header-host-exists/38915/6 "2008-02-07T11:03:36Z")

</div>

The wiki page for HTTP::header ([Click here](http://devcentral.f5.com/wiki/default.aspx/iRules/http__header)) indicates that if the header doesn’t exist already, it will be inserted, so Deb’s example should work perfectly.

Aaron
