# questions on HTTP::header replace Host

**URL:** <https://community.f5.com/t/questions-on-http-header-replace-host/39552>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [August 8, 2011, 4:12pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552 "2011-08-08T16:12:41Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 8, 2011, 4:12pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/1 "2011-08-08T16:12:41Z")

</div>

Hi,dear irule

I have 2 datacenters,due to some operation,we need to forward traffic on site1 to site2

site1 and site2 have the same domain name [www.cjj.com](http://www.cjj.com)

However ,they can be different in order to achieve goal of forwarding traffic

like [www1.cjj.com](http://www1.cjj.com) ,[www2.cjj.com](http://www2.cjj.com)(I can change something to achieve this)

for example ,clients visit [www.cjj.com](http://www.cjj.com) and hit site1,when bigip receive this traffic ,forward it to site2 and keep the broswer same as before.

how to achieve this?

I searched the irule here,HTTP::header replace Host are used more often than other methods

But I am confused by events below

when HTTP\_REQUEST {

if { [HTTP::header host] eq “[www.cjj.com](http://www.cjj.com)” } {

HTTP::header replace Host “[www2.cjj.com](http://www2.cjj.com)” }

}

when HTTP\_RESPONSE {

if { [HTTP::header is\_redirect]} {

HTTP::header replace Location [string map -nocase {[www.cjj.com](http://www.cjj.com) [www2.cjj.com](http://www2.cjj.com)} [HTTP::header value Location]] }

}

Here is my doubts:

1:why should we use HTTP\_RESPONSE to change the location?

2:should I set node xxx under HTTP::header replace Host “[www2.cjj.com](http://www2.cjj.com)”

like

HTTP::header replace Host “[www2.cjj.com](http://www2.cjj.com)”

node xxxxip xxport

3:what is the process of this command ,after excuting this replace,what is the behavior of bigip to handle traffic(I know http::redirect is bigip send 30x to client and the client send request to new URL )

4:how to achieve this goal :forward traffic which hit site1 to site2 ,can I not need two domain name to achieve this?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![The\_Bhattman](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/the_bhattman/32/13958_2.png) [@The\_Bhattman](https://community.f5.com/u/The_Bhattman)\
**Post date:** [August 8, 2011, 6:44pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/2 "2011-08-08T18:44:26Z")

</div>

Hi Jucao,

You would want to to use HTTP\_RESPONSE so that the client’s browser redirects to the site2, preserving the URI on the browser. Setting the node to site 2 will basically mean to connect to site2 you need to connect through site 1 LTM potentially adding latency to the client.

The following is an excellent article on HTTP Redirects and their many different ways to accomplish this with specific results

[http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/220/Rewriting-Redirects.aspx](http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/220/Rewriting-Redirects.aspx)

I hope this helps

Bhattman

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 9, 2011, 12:04am UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/3 "2011-08-09T00:04:27Z")

</div>

Hi,Bhattman,good to see u again

1:if I set replace in HTTP\_RESPONSE,what will bigip ip do

we don’t want the HTTP\_REQUEST to process the connection ,just when receive request,forward it to site2,but in this way,I think traffic will be handled by HTTP\_REQUEST first

2:sorry for my bad understanding,you mean

when HTTP\_REQUEST {

if { [HTTP::header host] eq “[www.cjj.com](http://www.cjj.com)” } {

HTTP::header replace Host “[www2.cjj.com](http://www2.cjj.com)”

nod xxxip xxport }

} is not good?

what is the action bigip will do if I set this HTTP\_REQUEST

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 9, 2011, 12:07am UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/4 "2011-08-09T00:07:54Z")

</div>

when HTTP\_RESPONSE {

if { [HTTP::is\_redirect] }{

HTTP::header replace Location [string map {“[A.internal.com](http://A.internal.com)” “[X.external.com](http://X.external.com)”} [HTTP::header Location]]

}

} is a method to change the location when there is a redirect

Actually in my case,there is no redirect,we need to generate a redirect…

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 9, 2011, 7:22am UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/5 "2011-08-09T07:22:33Z")

</div>

Hi,I want a irule to proxy site2 via site1

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [August 9, 2011, 9:14am UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/6 "2011-08-09T09:14:35Z")

</div>

2:sorry for my bad understanding,you mean

when HTTP\_REQUEST {

if { [HTTP::header host] eq “[www.cjj.com](http://www.cjj.com)” } {

HTTP::header replace Host “[www2.cjj.com](http://www2.cjj.com)”

nod xxxip xxport }

} is not good?

yes, Bhattman means it will add latency to client since traffic has to travel to site1 first and then site2. if u use HTTP::redirect, cilent will connect to site2 directly but uri in his browser will also be changed.

when HTTP\_RESPONSE {

if { [HTTP::is\_redirect] }{

HTTP::header replace Location [string map {“[A.internal.com](http://A.internal.com)” “[X.external.com](http://X.external.com)”} [HTTP::header Location]]

}

} is a method to change the location when there is a redirect

yes

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 9, 2011, 1:26pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/7 "2011-08-09T13:26:10Z")

</div>

Hi,

but there is no redirect now,

Can we generate a redirect ?

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 9, 2011, 1:29pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/8 "2011-08-09T13:29:37Z")

</div>

I want to redirect to site2 and keep the old url in browser

Can I achieve this?

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 9, 2011, 2:19pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/9 "2011-08-09T14:19:25Z")

</div>

Hi,friends

I want to use irule to redirect and use irule to keep old url in browser .It seems it is not possible

---

<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 10, 2011, 4:17pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/10 "2011-08-10T16:17:32Z")

</div>

No, that’s not possible in HTTP. You can either update the browser with a redirect or rewrite the request and send it through LTM to a destination.

Aaron

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 11, 2011, 12:26am UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/11 "2011-08-11T00:26:45Z")

</div>

Thanks,Aaron

if use rewrite and send it to another site2,there is a problem

VS:with client ssl profile ,without serverside ssl profile

it will send plain text to site2…because it thinks site2 is backend server

---

<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:** [August 15, 2011, 6:41pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/12 "2011-08-15T18:41:50Z")

</div>

You could selectively enable a serverside profile, couldn’t you?

---

<div class="post-metadata">

**Author:** ![Robert\_47833](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@Robert\_47833](https://community.f5.com/u/Robert_47833)\
**Post date:** [August 16, 2011, 1:56am UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/13 "2011-08-16T01:56:31Z")

</div>

ok,I think this is the only way to achieve this goal even it is too much to do ,need to enable ssl server profile and disable them in some case

Thanks

---

<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:** [August 16, 2011, 11:10pm UTC](https://community.f5.com/t/questions-on-http-header-replace-host/39552/14 "2011-08-16T23:10:51Z")

</div>

Yep, that’s the route I’d imagine would be most likely to succeed.

Colin
