Forum Discussion
Manuel_Rodrigu2
Nimbostratus
Jun 25, 2008Redirect to a different folder hosted by a different pool
Hi there,
Hope this can be done with an iRule. Basically when I receive requests for http://www.abc.com/hello I need to redirect them to http://www.abc.com/hello_1 hosted on a different pool, not the default.
Is it possible with an iRule?
Thanks
Manuel
5 Replies
- The_Bhattman
Nimbostratus
Hi Manual,
The following is VERY simple example of redirectwhen HTTP_REQUEST { if {HTTP::uri eq "hello" } { HTTP::redirect "http://www.abc.com/hello_1" } }
I hope this helps
CB - Manuel_Rodrigu2
Nimbostratus
Hi cmbhatt,
Thanks for the quick reply. Yes that would work if hello_1 was hosted by the same pool/servers. The problem here is that we need to send that request to a different pool (not the default) and the host is the same (www.abc.com).
Thanks again.
Manuel - Jose_Santiago_O
Nimbostratus
Hi Manuel,
You can try this:when HTTP_REQUEST { if {[string tolower [HTTP::uri]] equals "/hello" } { HTTP::uri "/hello_1" pool my_other_pool } else { pool my_default_pool } }
Regards. - Deb_Allen_18Historic F5 AccountIt's not clear whether you want to redirect or re-write the URI. josantia's solution re-writes the URI, but only for exactly that URI.
If you want to re-write the existing URI by simply replacing the name of the first directory, you can do it like this:when HTTP_REQUEST { if {[getfield [string tolower [HTTP::uri]] "/" 2] equals "hello" } { HTTP::uri [string map {"/hello" "/hello_1"} [HTTP::uri]] pool my_other_pool } else { pool my_default_pool } }
If you want to redirect the same way (preserving the URI), you can do it like this:when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/hello1*" { pool my_other_pool } "/hello*" { HTTP::redirect "http://[HTTP::host]/hello_1[substr [HTTP:uri] 6]" } default { pool my_default_pool } } }
/deb - Deb_Allen_18Historic F5 AccountOops, sorry, that first example doesn't work since the first directory is a substring. of the 2nd. Adjusted to extract the first directory name with getfield instead of using starts_with
/d
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
