HTTP::header replace Host and HTTP:redirect

Hi,dear irule

1:if there are rule1 and rule2 under one VS,order is rule1 and rule2

rule1:

when HTTP:request {

if { [HTTP::host] euqals “www.srwd18.com”} {

HTTP::redirect “http://www.baidu.com”

}

}

rule2

when HTTP::request {

if {[HTTP::host] equals “www.srwd18.com”} {

HTTP::redirect “http://www.google.com”

}

}

so if someone visit www.srwd18.com,client will go to www.google.com or where?

how to turn off rule2,I only know return will jump out of the current event in single irule.

2:if I use HTTP::header replace Host “www.baidu.com” to rewrite the request

it seems this will not change the item in broswer,such as IE

so bigip will visit www.baidu.com for client,right?like a proxy

when HTTP::REQUEST {

if {[HTTP::host] equals “www.srwd18.com”}{

HTTP::header replace Host “www.baidu.com”

return}

}

it doesn’t work

overall:What I am trying to achieve is:

there are 2 datacenter, same website ,if I want to forward traffic in site1 to site2 ,how to forward them?

The only way I can think about is HTTP::REDIRECT,but this will change the item/address in client’s broswer

so it seems HTTP::header replace Host is a good choice,

Can some one help me?

Thanks in advance,

so if someone visit www.srwd18.com,client will go to www.google.com or where?

i think so - he would be redirected to google.com

how to turn off rule2,I only know return will jump out of the current event in single irule.

have u seen these?

Stacking iRules: A Modular Approach by Deb

http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/240/Stacking-iRules-A-Modular-Approach.aspx

iRules: Disabling Event Processing by Deb

http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/236/iRules-Disabling-Event-Processing.aspx

2:if I use HTTP::header replace Host “www.baidu.com” to rewrite the request

it seems this will not change the item in broswer,such as IE

yes

so bigip will visit www.baidu.com for client,right?like a proxy

no, i don’t think so. what bigip does is to replace host header in request to “www.baidu.com”.

there are 2 datacenter, same website ,if I want to forward traffic in site1 to site2 ,how to forward them?

The only way I can think about is HTTP::REDIRECT,but this will change the item/address in client’s broswer

so it seems HTTP::header replace Host is a good choice,

can’t it be done by gtm?

Hi,nitass

Thanks for your help

I have tried in my lab,

:if there are rule1 and rule2 under one VS,order is rule1 and rule2

rule1:

when HTTP:request {

if { [HTTP::host] euqals “www.srwd18.com”} {

HTTP::redirect “http://www.baidu.com”

}

}

rule2

when HTTP::request {

if {[HTTP::host] equals “www.srwd18.com”} {

HTTP::redirect “http://www.google.com”

}

}

so if someone visit www.srwd18.com,client will go to www.google.com or where?

------it can’t show the page,I don’t know why

2:

yes

so bigip will visit www.baidu.com for client,right?like a proxy

no, i don’t think so. what bigip does is to replace host header in request to “www.baidu.com”.

-----bigip worked as a full proxy server,so after it change replace host to “www.baidu.com”,it will send request to “www.baidu.com”,however rule below doesn’t work

when HTTP::REQUEST {

if {[HTTP::host] equals “www.srwd18.com”}{

HTTP::header replace Host “www.baidu.com”

return}

}

3:

there are 2 datacenter, same website ,if I want to forward traffic in site1 to site2 ,how to forward them?

The only way I can think about is HTTP::REDIRECT,but this will change the item/address in client’s broswer

so it seems HTTP::header replace Host is a good choice,

can’t it be done by gtm?

-----some downstream dns server ignore the TTL set in GTM.so they cache the record more than TTL ,maybe 24 hours,

that is why I try to achieve via redirect or forward

Do u have some method to achieve this

so if someone visit www.srwd18.com,client will go to www.google.com or where?

------it can’t show the page,I don’t know why

sorry i’m wrong. both events are triggered but user gets the first redirection since multiple redirections aren’t supported.

[root@tulip:Active] config b virtual bar list

virtual bar {

pool foo

destination 172.28.17.66:http

ip protocol tcp

rules

rule1

rule2

profiles

http

tcp

}

[root@tulip:Active] config b rule rule1 list

rule rule1 {

when HTTP_REQUEST {

log local0.info “rule1”

if {[HTTP::host] equals “www.srwd18.com”} {

HTTP::redirect “http://www.baidu.com”

}

}

}

[root@tulip:Active] config b rule rule2 list

rule rule2 {

when HTTP_REQUEST {

log local0.info “rule2”

if {[HTTP::host] equals “www.srwd18.com”} {

HTTP::redirect “http://www.google.com”

}

}

}

[root@tulip:Active] config curl -i http://www.srwd18.com/

HTTP/1.0 302 Found

Location: http://www.baidu.com

Server: BigIP

Connection: Keep-Alive

Content-Length: 0

[root@tulip:Active] config tail -f /var/log/ltm

Aug 7 05:27:47 tmm tmm[1843]: Rule rule1 : rule1

Aug 7 05:27:47 tmm tmm[1843]: Rule rule2 : rule2

Aug 7 05:27:47 tmm tmm[1843]: 01220001:3: TCL error: rule2 - Operation not supported. Multiple redirect/respond invocations not allowed (line 3) invoked from within "HTTP::redirect “http://www.google.com” "

Hi,

yes,it is not supported,

so how to make irule below work

when HTTP::REQUEST {

if {[HTTP::host] equals “www.srwd18.com”}{

HTTP::header replace Host “www.baidu.com”

return}

}

or how to reslove

there are 2 datacenter, same website ,if I want to forward traffic in site1 to site2 ,how to forward them?

The only way I can think about is HTTP::REDIRECT,but this will change the item/address in client’s broswer

so it seems HTTP::header replace Host is a good choice,

can’t it be done by gtm?

-----some downstream dns server ignore the TTL set in GTM.so they cache the record more than TTL ,maybe 24 hours,

that is why I try to achieve via redirect or forward

Do u have some method to achieve this

can u try to add pool or node command in the irule to send traffic to another site?

[root@tulip:Active] config b virtual bar list

virtual bar {

destination 172.28.17.66:http

ip protocol tcp

rules rule1

profiles

http

tcp

}

[root@tulip:Active] config b rule rule1 list

rule rule1 {

when HTTP_REQUEST {

log local0.info “rule1”

if {[HTTP::host] equals “www.srwd18.com”} {

snat automap

node 220.181.111.147 80

HTTP::header replace Host “www.baidu.com”

}

}

}

[root@tulip:Active] config curl -IL http://www.srwd18.com/

HTTP/1.1 200 OK

Date: Sun, 07 Aug 2011 16:31:46 GMT

Server: BWS/1.0

Content-Length: 7410

Content-Type: text/html;charset=gb2312

Cache-Control: private

Expires: Sun, 07 Aug 2011 16:31:46 GMT

Set-Cookie: BAIDUID=63CB57D21D237F0DF3EB449022233FC0:FG=1; expires=Sun, 07-Aug-41 16:31:46 GMT; path=/; domain=.baidu.com

P3P: CP=" OTI DSP COR IVA OUR IND COM "

Connection: Keep-Alive

New TCP connection 8: 172.28.17.60(33128) ↔ 172.28.17.66(80)

1312733826.7271 (0.0001) C>S

---------------------------------------------------------------

HEAD / HTTP/1.1

User-Agent: curl/7.15.3 (i686-redhat-linux-gnu) libcurl/7.15.3 OpenSSL/0.9.7l zlib/1.1.4

Host: www.srwd18.com

Accept: */*

New TCP connection 9: 172.28.17.60(33128) ↔ 220.181.111.147(80)

1312733826.7283 (0.0011) C>S

---------------------------------------------------------------

HEAD / HTTP/1.1

User-Agent: curl/7.15.3 (i686-redhat-linux-gnu) libcurl/7.15.3 OpenSSL/0.9.7l zlib/1.1.4

Host: www.baidu.com

Accept: */*

---------------------------------------------------------------

1312733827.0685 (0.3401) S>C

---------------------------------------------------------------

HTTP/1.1 200 OK

Date: Sun, 07 Aug 2011 16:31:46 GMT

Server: BWS/1.0

Content-Length: 7410

Content-Type: text/html;charset=gb2312

Cache-Control: private

Expires: Sun, 07 Aug 2011 16:31:46 GMT

Set-Cookie: BAIDUID=63CB57D21D237F0DF3EB449022233FC0:FG=1; expires=Sun, 07-Aug-41 16:31:46 GMT; path=/; domain=.baidu.com

P3P: CP=" OTI DSP COR IVA OUR IND COM "

Connection: Keep-Alive

Hi,

[root@tulip:Active] config b rule rule1 list

rule rule1 {

when HTTP_REQUEST {

log local0.info “rule1”

if {[HTTP::host] equals “www.srwd18.com”} {

snat automap

node 220.181.111.147 80

HTTP::header replace Host “www.baidu.com”

}

}

}

--but pool is in another datacenter,how can I add them in this datacenter?

Also,there are so many pools under this VS and need to forward to site2 and let site2’s irule process the traffic.

Can I use VIP in this position?

you use GTM to work around this before?

--but pool is in another datacenter,how can I add them in this datacenter?

Also,there are so many pools under this VS and need to forward to site2 and let site2’s irule process the traffic.

Can I use VIP in this position?

for my testing, 220.181.111.147 is vip on another site e.g. site2.

you use GTM to work around this before?

i don’t know much about gtm. anyway, i understand gtm can decide should cilent connect to vip on site1 or site2.

OK,nitass,I will try this now

Can u give me the process how bigip handle this? HTTP::header replace Host “www.baidu.com”

it seems there is no http 302 or something like this

btw:GTM can decide client go to site1 or site2

However some downstream ignore the TTL set in gtm,so they will keep the old value of DNS record

So they will still go to site1

and there are 2 FTP VS,how to redirect them?

besides this, when HTTP_REQUEST {

log local0.info “rule1”

if {[HTTP::host] equals “www.srwd18.com”} {

node 220.181.111.147 80

HTTP::header replace Host “www.baidu.com”

}

only can send http request to site2 ,if no ssl server profile set in VS of site1,it will not work

do we will have cookie issue if we use http::header replace?

Can u give me the process how bigip handle this? HTTP::header replace Host “www.baidu.com”

it seems there is no http 302 or something like this

i have seen Colin has answered this question there.

http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1179184/showtab/groupforums/Default.aspx

and there are 2 FTP VS,how to redirect them?

i think the problem is how we get ftp hostname (since u want to redirect to site2 based on the hostname).

this is tcpdump when i connected to ftp server.

220 (vsFTPd 2.0.6)

USER anonymous

331 Please specify the password.

PASS

230 Login successful.

PORT 192,168,206,96,202,69

200 PORT command successful. Consider using PASV.

NLST

150 Here comes the directory listing.

226 Directory send OK.

this is one of discussion topics i have found.

http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/25911/showtab/groupforums/Default.aspx

only can send http request to site2 ,if no ssl server profile set in VS of site1,it will not work

do we will have cookie issue if we use http::header replace?

sorry i could not understand. can u post your virtual config here?

only can send http request to site2 ,if no ssl server profile set in VS of site1,it will not work

do we will have cookie issue if we use http::header replace?

sorry i could not understand. can u post your virtual config here?

------for example ,in site 1 , there is a VS which only has client side ssl profile ,same as VS in site2

if I use

if {[HTTP::host] equals “www.srwd18.com”} {

node 220.181.111.147 80

HTTP::header replace Host “www.baidu.com”

then plain text will be sent to site2,because I don’t have ssl server side profile.

Hi,nitass

do we have command to redirect ftp VS?

I know the hostname ,it is static

thanks in advance