Forum Discussion
Rajesh_A_142089
Jan 24, 2014Nimbostratus
Conditional Redirection
My use case for iRule:
iRule on Source_Host VIP If Source_Host response is 404 then redirect to Target_Host.
iRule on Target_Host VIP If Current Request is a Redirect and current response i...
- Jan 25, 2014
e.g.
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } rules { qux } source 0.0.0.0/0 source-address-translation { type automap } vs-index 8 } root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo ltm pool foo { members { 200.200.200.101:80 { address 200.200.200.101 } } } root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [HTTP::host] eq "sourcehost.mydomain.com" } { set is_sourcehost 1 set uri [HTTP::uri] } else { set is_sourcehost 0 } } when HTTP_RESPONSE { if { $is_sourcehost and [HTTP::status] == 404 } { HTTP::respond 302 noserver Location "http://targethost.mydomain.com$uri" } } } [root@centos1 ~] curl -i http://172.28.24.10/something -H "Host: sourcehost.mydomain.com" HTTP/1.0 302 Found Location: http://targethost.mydomain.com/something Connection: Keep-Alive Content-Length: 0
nitass_89166
Noctilucent
e.g.
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
destination 172.28.24.10:80
ip-protocol tcp
mask 255.255.255.255
pool foo
profiles {
http { }
tcp { }
}
rules {
qux
}
source 0.0.0.0/0
source-address-translation {
type automap
}
vs-index 8
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
ltm pool foo {
members {
200.200.200.101:80 {
address 200.200.200.101
}
}
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
ltm rule qux {
when HTTP_REQUEST {
if { [HTTP::host] eq "sourcehost.mydomain.com" } {
set is_sourcehost 1
set uri [HTTP::uri]
} else {
set is_sourcehost 0
}
}
when HTTP_RESPONSE {
if { $is_sourcehost and [HTTP::status] == 404 } {
HTTP::respond 302 noserver Location "http://targethost.mydomain.com$uri"
}
}
}
[root@centos1 ~] curl -i http://172.28.24.10/something -H "Host: sourcehost.mydomain.com"
HTTP/1.0 302 Found
Location: http://targethost.mydomain.com/something
Connection: Keep-Alive
Content-Length: 0
Rajesh_A_142089
Jan 28, 2014Nimbostratus
Thank you Nitass, your example helped me to implement what I was looking for. Here is my code example for others.
-----iRule on Source Farm-------
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] eq "source.mydomain.com"}{
set is_sourcehost 1
set uri [HTTP::uri]
} else {
set is_sourcehost 0
}
}
----If source farm is not responding then redirect to target farm----------
when HTTP_RESPONSE {
if { $is_sourcehost and [HTTP::status] == 404 } {
HTTP::respond 302 noserver Location "https://target.mydomain.com$uri"
}
}
-----End of rule-------
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