Bertolazzi_7869
Apr 18, 2012Nimbostratus
HTTP Redirect: Hint or an example?
Redirect vs. Rewrite
http://cheeso.members.winisp.net/iirf20Help/html/2e820208-c2eb-4d6d-a134-c63f7d41244f.htm
this is an example of redirection.
[root@ve1023:Active] config b virtual bar list
virtual bar {
snat automap
pool server
destination 172.28.19.79:8080
ip protocol 6
rules myrule
profiles {
http {}
tcp {}
}
}
[root@ve1023:Active] config b rule myrule list
rule myrule {
when HTTP_REQUEST {
if { [HTTP::uri] equals "/ABC" } {
HTTP::redirect "http://[HTTP::host]/DEF"
}
}
}
[root@ve1023:Active] config curl -I http://www.mydomain.com:8080/ABC
HTTP/1.0 302 Found
Location: http://www.mydomain.com:8080/DEF
Server: BigIP
Connection: Keep-Alive
Content-Length: 0
Try this:
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/abc" } {
HTTP::redirect [string map {"abc" "def"} [HTTP::uri]]
}
}
This iRule some assume that you just want to replace the sub-directory "abc" with "def" and keep the rest of the HTTP::uri.
If you are needing something else just let us know.
Hope this helps.
I will test now and post the results.
The redirection works fine with Nitass code!
Please, tell me if this configuration is correct:
http://www.mydomain.com:8080/ABC redirects to http://www.mydomain.com:8080/DEF and points to the pool pool_def
http://www.mydomain.com:8080/HIJ redirects to http://www.mydomain.com:8080/KLM and points to the pool pool_klm
when HTTP_REQUEST {
if { [HTTP::uri] equals "/abc" } {
HTTP::redirect "http://[HTTP::host]/def"{
"/abc*" {pool pool_def}
}
}
if { [HTTP::uri] equals "/hij" } {
HTTP::redirect "http://[HTTP::host]/klm"{
"/hij*" {pool pool_klm}
}
}
}
tks.
I searched here in the forum and found a thread on redirection to pool, so I created two iRules.
1º - iRule - pool redirection
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/abc*" {pool pool_def}
"/hij*" {pool pool_klm}
}
}
2º iRule - http redirection
when HTTP_REQUEST {
if { [HTTP::uri] equals "/abc" } {
HTTP::redirect "http://[HTTP::host]/def/"
}
if { [HTTP::uri] equals "/hij" } {
HTTP::redirect "http://[HTTP::host]/klm/"
}
}
I was successful in the tests that I performed, but i don't know if this way is the best.
I will continue performing the tests and keep everyone updated.
Tks.
e.g.
[root@ve1023:Active] config b rule myrule list
rule myrule {
when HTTP_REQUEST {
switch [HTTP::uri] {
"/ABC" { HTTP::redirect "http://[HTTP::host]/DEF" }
"/HIJ" { HTTP::redirect "htt://[HTTP::host]/KLM" }
"/DEF" { pool pool_def }
"/KLM" { pool pool_klm }
}
}
}
I tested with your iRule and worked.
Tks.