Forum Discussion
Peak_10_71174
Nimbostratus
Oct 27, 2009http redirect if no path match irule
I need to create an irule that accomplishes 2 things:
When incoming http requests for data.abc.com are received on a virtual server, they are redirected to www.abc.com/data. However, when a user requests data.abc.com/file.exe directly, that http request is then directed to the server pool on the load balancer that the virtual server is associated with. Below is my first attempt at writing this rule, but I am posting it on here because I am far from an expert in writing irules.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::path]] {
"data.abc.com/file.exe" {
pool data_pool
log local0. "HTML hit - data_pool chosen"
}
default {
HTTP::redirect "http://www.abc.com/data"
log local0. "redirect_chosen."
}
}
}
I used the switch command in this attempt, but I am in no way certain that this is the best way to accomplish this.
- hoolio
Cirrostratus
HTTP::path will return the path in the URI (URI minus the query string). It will not include the host. HTTP::host will return the host header value. So you can remove data.abc.com from your rule and it should work fine. - Matt_H_58911
Nimbostratus
I would like to propose another way. Will this work? - hoolio
Cirrostratus
Hi Matt, - Matt_H_58911
Nimbostratus
Hoolio, - JRahm
Admin
So, IF host = data.abc.com AND uri = /, redirect to www.abc.com/data?when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "data.abc.com" && [HTTP::uri] eq "/" } { HTTP::redirect "http://www.[domain [HTTP::host] 2]/[getfield [HTTP::host] "." 1]" } }
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