Forum Discussion

winnajeem_25540's avatar
winnajeem_25540
Icon for Nimbostratus rankNimbostratus
Mar 23, 2016

redirect loop

Hi All.

 

Request help to resolve redirect loop.

 

when HTTP_REQUEST { if { [string tolower [HTTP::host]] contains "abc.com"} { if { not ([HTTP::uri] contains "/abc/en") or not ([HTTP::uri] equals "/") } then { HTTP::redirect "http://[HTTP::host]" } } }

 

When the above irule is activated, abc.com/abc/en/* works fine, but when the http_host does not have any uri the irule is going into redirect loop.

 

abc.com -> abc.com -> abc.com -> .....

 

how can we resolve the redirect loop when uri is empty.

 

2 Replies

  • Your problem is the HTTP::redirect "http://[HTTP::host]" statement. If you don't match the terms stated (contains /abc/en or equals / ) then you are telling the iRule to redirect to http://abc.com The redirected request hits the iRule, and then hits the redirect statement again. Why have you got the redirect in there? What are you trying to achieve?
  • Hi Winnajeem,

    the problem with your iRule is that "(not /) or not (/abc/en)" is alway true and therefor hits the redirect everytime.

    To fix the redirect loop, you may try the iRule below...

    when HTTP_REQUEST { 
        if { [string tolower [HTTP::host]] contains "abc.com"} then { 
            if { ([string tolower [HTTP::uri]] starts_with "/abc/en") or ([HTTP::uri] equals "/") } then { 
                 Do nothing
            } else {
                HTTP::redirect "http://[HTTP::host]" 
            }
        } 
    }
    

    Cheers, Kai