Forum Discussion
dyobbs_25515
Nimbostratus
Feb 03, 2012iRule to redirect a variable to http
Guys hi,
I'm newbie here. I wanted to create an iRule, that truncates the later part of the message from the "http://.acme.com" to http://
any help is appreciated.
Will this work?
when HTTP_REQUEST {
if { [HTTP::uri] starts_with ".acme.com" } {
HTTP::redirect "http://[HTTP::host]"
}
24 Replies
- nitass
Employee
can you post the question again? some text is missing because of devcentral's parser.
by the way, acme.com is not part of HTTP::uri. it is part of HTTP::host.
5-Minute iRules: What’s a URL?
http://devcentral.f5.com/weblogs/jason/archive/2010/09/29/5-minute-irules-whatrsquos-a-url.aspx
anyway, this is what i guess you are asking.
[root@ve1023:Active] config b virtual bar list
virtual bar {
destination 172.28.19.79:80
ip protocol 6
rules myrule
profiles {
http {}
tcp {}
}
}
[root@ve1023:Active] config b rule myrule list
rule myrule {
when HTTP_REQUEST {
if {[scan [HTTP::host] {%[^.].acme.com} first] == 1}{
HTTP::redirect "]"
}
}
}
[root@ve1023:Active] config curl -I http://test.acme.com/whatever
HTTP/1.0 302 Found
Location:
Server: BigIP
Connection: Keep-Alive
Content-Length: 0 - dyobbs_25515
Nimbostratus
Hi thanks!
Here's the question -> convert http://XXXX.acme.com.nz ---------> http://XXXXX
you truncate acme.com.nz.
========
Yup that's it!
that was fast, thanks nitass. - dyobbs_25515
Nimbostratus
Nitass hi,
How do i test this, if i have only VE Edition for LTM?
thanks! - nitass
Employee
can you map "xxxx.acme.com.nz" and "xxxx" to same ip address which is virtual server address in local hosts file on client? - dyobbs_25515
Nimbostratus
Nitass hi,
Initially it worked, i put the names and ip on the hosts file, but got some queries:
My results with the iRule:
www.yahoo.com.acme.com.nz ----returns to ->" www" only..it should be: "www.yahoo.com"
www.yahoo.com.au.acme.com.nz/issue/jan2012/default.htm -- does not work.. :( should be: "www.yahoo.com.au/issue/jan2012/default.htm"
appreciate your help. thanks! - nitass
Employee
please feel free to revise.[root@ve1023:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set host [string tolower [HTTP::host]] set newhost [string map {".acme.com.nz" ""} $host] if {$host ne $newhost} { HTTP::redirect "http://$newhost[HTTP::uri]" } } } [root@ve1023:Active] config curl -I http://172.28.19.79/whatever -H "Host: xxxx.acme.com.nz" HTTP/1.0 302 Found Location: http://xxxx/whatever Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve1023:Active] config curl -I http://172.28.19.79/whatever -H "Host: www.yahoo.com.acme.com.nz" HTTP/1.0 302 Found Location: http://www.yahoo.com/whatever Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve1023:Active] config curl -I http://172.28.19.79/whatever -H "Host: www.yahoo.com.au.acme.com.nz" HTTP/1.0 302 Found Location: http://www.yahoo.com.au/whatever Server: BigIP Connection: Keep-Alive Content-Length: 0 - dyobbs_25515
Nimbostratus
Thanks Nitass! but somehow only works on Google Chrome.
IE and firefox, does not redirect.
Any settings to put on the said browsers? - nitass
Employee
IE and firefox, does not redirect.
Any settings to put on the said browsers?i have no idea yet.
by the way, have you ever used http analyzer tool?
HttpFox
https://addons.mozilla.org/en-US/firefox/addon/httpfox/ - dyobbs_25515
Nimbostratus
Cool stuff, now i can monitor. Works now. Thanks Nitass! - Kalpesh_48932
Nimbostratus
Hello...I have one problem for setting up an iRule (i m new for iRule)
I have requirement that when one of the pool member is Down of VIP, then the connection should redirect to HTTP://Sorry page..
for eg: if pool is ' Pool_Test_Sorry_Alfresco' and url is 'http://dev-sorry-webarch.xyz.com'..then how to set iRule to get this result...
Please provide solution....
Thanks in Advance
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
