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
e.g.[root@ve1023:Active] config b virtual bar list virtual bar { snat automap pool Pool_Test_Sorry_Alfresco destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve1023:Active] config b pool Pool_Test_Sorry_Alfresco list pool Pool_Test_Sorry_Alfresco { monitor all http members 200.200.200.101:80 {} } [root@ve1023:Active] config b pool Pool_Test_Sorry_Alfresco|grep -i pool\ member +-> POOL MEMBER Pool_Test_Sorry_Alfresco/200.200.200.101:80 active,up [root@ve1023:Active] config curl -I http://172.28.19.79 HTTP/1.1 200 OK Date: Thu, 09 Feb 2012 15:25:01 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Fri, 11 Nov 2011 14:48:14 GMT ETag: "4183e4-3e-9c564780" Accept-Ranges: bytes Content-Length: 62 Content-Type: text/html; charset=UTF-8 [root@ve1023:Active] config b pool Pool_Test_Sorry_Alfresco monitor all fake [root@ve1023:Active] config b pool Pool_Test_Sorry_Alfresco|grep -i pool\ member +-> POOL MEMBER Pool_Test_Sorry_Alfresco/200.200.200.101:80 inactive,down [root@ve1023:Active] config curl -I http://172.28.19.79 HTTP/1.0 302 Found Location: http://dev-sorry-webarch.xyz.com Server: BigIP Connection: Keep-Alive Content-Length: 0 - dyobbs_25515
Nimbostratus
Nitass hi,
When i used F5 as a proxy. I defined the proxy address in my browser.
Somehow it returned the web address like this:
http://www.nba.comhttp//www.nba.com.acme.com.nz/
any info is appreciated. thanks! - nitass
Employee
it is because header is different when requesting directly and using explicit proxy.this is directly request. [root@ve1023:Active] config ssldump -Aed -nni 0.0 port 80 Feb 13 02:26:36 local/tmm notice tmm[4822]: 013e0001:5: Tcpdump starting bcast on :::0 from 127.1.1.1:34917 New TCP connection 1: 172.28.19.251(45151) <-> 172.28.19.79(80) 1329128801.9948 (0.0009) C>S --------------------------------------------------------------- HEAD /whatever HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Accept: */* Host: www.yahoo.com.acme.com.nz --------------------------------------------------------------- this is request with f5 as an explicit proxy. [root@ve1023:Active] config ssldump -Aed -nni 0.0 port 80 Feb 13 02:27:30 local/tmm notice tmm[4822]: 013e0001:5: Tcpdump starting bcast on :::0 from 127.1.1.1:57671 New TCP connection 1: 172.28.19.251(45152) <-> 172.28.19.79(80) 1329128868.8840 (0.0012) C>S --------------------------------------------------------------- HEAD http://www.yahoo.com.acme.com.nz/whatever HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Host: www.yahoo.com.acme.com.nz Pragma: no-cache Accept: */* Proxy-Connection: Keep-Alive --------------------------------------------------------------- this is an example irule when using f5 as an explicit proxy. [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 { set host [string tolower [HTTP::host]] set proxy_uri [string tolower [HTTP::uri]] set uri [getfield $proxy_uri $host 2] set newhost [string map {".acme.com.nz" ""} $host] if {$host ne $newhost} { HTTP::redirect "http://$newhost$uri" } } } [root@ve1023:Active] config curl -I http://www.yahoo.com.acme.com.nz/whatever -x 172.28.19.79:80 HTTP/1.0 302 Found Location: http://www.yahoo.com/whatever Server: BigIP Connection: Keep-Alive Content-Length: 0 - Kalpesh_48932
Nimbostratus
Hello Nitass..Thanks for this configuration..but can you give me config to be used in webconsole..not on command line... - nitass
Employee
hi Kalpesh,
what configuration are you talking about? is it the one i posted on 02/09/2012 11:22 PM? - Kalpesh_48932
Nimbostratus
02/09/2012 03:21 PM - Kalpesh_48932
Nimbostratus
e.g.
[root@ve1023:Active] config b virtual bar list
virtual bar {
snat automap
pool Pool_Test_Sorry_Alfresco
destination 172.28.19.79:80
ip protocol 6
rules myrule
profiles {
http {}
tcp {}
}
}
[root@ve1023:Active] config b pool Pool_Test_Sorry_Alfresco list
pool Pool_Test_Sorry_Alfresco {
monitor all http
members 200.200.200.101:80 {}
}
[root@ve1023:Active] config b pool Pool_Test_Sorry_Alfresco|grep -i pool\ member
+-> POOL MEMBER Pool_Test_Sorry_Alfresco/200.200.200.101:80 active,up
[root@ve1023:Active] config curl -I http://172.28.19.79
HTTP/1.1 200 OK
Date: Thu, 09 Feb 2012 15:25:01 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Fri, 11 Nov 2011 14:48:14 GMT
ETag: "4183e4-3e-9c564780"
Accept-Ranges: bytes
Content-Length: 62
Content-Type: text/html; charset=UTF-8
[root@ve1023:Active] config b pool Pool_Test_Sorry_Alfresco monitor all fake
[root@ve1023:Active] config b pool Pool_Test_Sorry_Alfresco|grep -i pool\ member
+-> POOL MEMBER Pool_Test_Sorry_Alfresco/200.200.200.101:80 inactive,down
[root@ve1023:Active] config curl -I http://172.28.19.79
HTTP/1.0 302 Found
Location: http://dev-sorry-webarch.xyz.com
Server: BigIP
Connection: Keep-Alive
Content-Length: 0
*******************************************************************************************************
How to use it in web console....? - nitass
Employee
How to use it in web console....?oh sorry i just noticed i forgot to post the irule.when HTTP_REQUEST { if {[active_members [LB::server pool]] < 1} { HTTP::redirect "http://dev-sorry-webarch.xyz.com" } }
to create irule, go to local traffic > irules > irule list, create and copy-and-paste the irule above.
to assign irule to virtual server, go to local traffic > virtual servers > virtual-server-name > resource (2nd tab) > irules, manages and enable the created irule.
hope this helps. - Kalpesh_48932
Nimbostratus
This is the rule I have..but I have to use HTTP_referrer in it..........., i would like to have as http_referrer (which is used for that : _http://en.wikipedia.org/wiki/HTTP_referer) wth the original DNS called - dyobbs_25515
Nimbostratus
Nitass hi,
Given the irule:
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]"
}
}
using httpwatch, there's a response header that says HTTP/1.0 302 found
Location: http://
Can this maintain persistent session? Any traffic that goes into this iRule should have persistent session on the cache servers.
What can we put in?
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
