Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

iRule Redirect loop

southern_shred1
Nimbostratus
Nimbostratus

Hi

 

I am trying to achieve a simple URL redirect but I keep getting a redirect loop or nothing at all. I get an error of "too many redirects"

 

Condition 1

 

All requests to "; must be redirected to https://test.tst.train123.com/trace123 only

 

But any other traffic eg. "; must continue to the default pool

 

My problem is when I use the the irule below I get a redirect loop

 

when HTTP_REQUEST { if { [HTTP::host] equals "test.tst.train123.com" } { HTTP::redirect "https://test.tst.train123.com/Trace123 [HTTP::uri]" } }

 

When I try this it doesnt seem to work either. I know I am missing something

 

when HTTP_REQUEST { if { [HTTP::uri] equals "test.tst.train123.com"} { HTTP::redirect "/Trace123" } elseif { [HTTP::uri] equals "; } { pool pool_trace123 } }

 

2 REPLIES 2

JG
Cumulonimbus
Cumulonimbus

Not totally sure of your requirement, but I will still a venture a reply, if only serving as a pointer:

when HTTP_REQUEST {
    if { [HTTP::host] equals "test.tst.train123.com" } {
        switch -exact [string tolower [HTTP::path]] {
            "/" {
                     HTTP::redirect "https://test.tst.train123.com/Trace123"
            }
            default {
                        pool pool_trace123
            }
        }
    }
}

An LTM policy would actually be a better option, and its building process would guide you through it in a more transparent way and therefore be helpful to you.

[Edited]

Stanislas_Piro2
Cumulonimbus
Cumulonimbus

Hi,

 

if the virtual server only provides service for host test.tst.train123.com, use following code :

 

when HTTP_REQUEST {
    if {[HTTP::path] equals "/" } {
        HTTP::redirect "/Trace123"
    }
}

else you must filter on the host header

 

when HTTP_REQUEST {
    if { [HTTP::host] equals "test.tst.train123.com" && [HTTP::path] equals "/" } {
        HTTP::redirect "/Trace123"
    }
}

if not required by hostname change or protocol change (http to https redirect), please use "relative URL absolute path" URI in redirect (without protocol and host, but full path)