cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP::redirect loop

Gerald_Meese
Altostratus
Altostratus

Hello,

 

I'm trying to write a small iRule to create redirects to specific paths on an internal server based on the presence/absence of the 'order' parameter in the requested URI :

 

when HTTP_REQUEST { if { [HTTP::uri] contains "order" } { HTTP::redirect /Login.aspx?guestlogin=1&order=[URI::query [HTTP::uri] order]&context=3 } else { HTTP::redirect /Login.aspx?guestlogin=1 }

}

 

When I'm testing the iRule I'm running into a loop of "too many redirects" but I don't see what I need to do to correct that... Any help would be highly appreciated !

 

Thanks in advance 🙂

 

Gerald

 

2 REPLIES 2

youssef1
Cumulonimbus
Cumulonimbus

Hi Gerald,

 

Your Irule is not correct because it will trigged to each request. either at condition "if" or in each case at "else".

 

when HTTP_REQUEST { if { [HTTP::uri] contains "order" } { HTTP::redirect /Login.aspx?guestlogin=1&order=[URI::query [HTTP::uri] order]&context=3 } else { HTTP::redirect /Login.aspx?guestlogin=1 } }

You need to add an additional condition on else like this:

 

when HTTP_REQUEST { if { [HTTP::uri] contains "order" } { HTTP::redirect /Login.aspx?guestlogin=1&order=[URI::query [HTTP::uri] order]&context=3 } elseif {[HTTP::uri] eq "/"} { HTTP::redirect /Login.aspx?guestlogin=1 } }

le me now if it's clear...

 

Regards

 

Stanislas_Piro2
Cumulonimbus
Cumulonimbus

Here is a code which will prevent redirect loops

 

when HTTP_REQUEST { Make sure only the login page matches the code, to prevent all requests to be redirected to login page (like images CSS, and other web pages) if {[HTTP::path] equals "/Login.aspx"} { set order [URI::query [HTTP::uri] order] set context [URI::query [HTTP::uri] context] Don't redirect if context already equals 3 if { $order ne "" && $context != 3 } { HTTP::redirect /Login.aspx?guestlogin=1&order=${order}&context=3 Redirect if order is null and guestlogin doesn't equal 1 } elseif {$order == "" && [URI::query [HTTP::uri] guestlogin] ne 1} { HTTP::redirect /Login.aspx?guestlogin=1 } } }