redirection and cookies

Please help with this if you can… any suggestions about solving this issue are welcomed. Thank you for your time.

If a user from x ip address(es) connects to http://almstage.domain.com they are redirected to a page telling them to use a different method of accessing this resource (windows terminal servers), after 30 seconds the page redirects back to http://almstage.domain.com/qcbin/ and can access the webpage like anyone else for x amount of time. If a user from any ip type in http://almstage.domain.com they will automagically get redirected to http://almstage.domain.com/qcbin/.

http://almstage.domain.com/qcbin/index.jsp -- is where this app lives

http://almstage.domain.com/qcbin/WTSannouncement.htm - this is where the redirect page lives.

When I try the following code I get a redirection loop and a cookie is never set… if I comment out HTTP::redirect “http://almstage.domain.com/qcbin/WTSannouncement.htm” under the HTTP_response the cookie gets set and everything works fine. The code probably has redundancy when it comes to the cookie timeout.

when CLIENT_ACCEPTED {

Settings

set need_cookie0

set base_time [clock seconds]

set session_timeout 600

set cookie “cttiverify”

}

when HTTP_REQUEST {

log local0. “Redirect_cookie rule active”

if { [IP::client_addr] equals “10.60.249.237” } {

log local0. “matched ip”

if { [HTTP::cookie exists $cookie]} {

log local0. “we have a cookie”

set cookie_time [HTTP::cookie $cookie]

if {[expr $base_time - $cookie_time] > $session_timeout } {

set need_cookie1

log local0. “cookie is old - set cookie is $need_cookie”

HTTP::cookie insert name $cookie value $base_time path “/”

HTTP::redirect “http://almstage.domain.com/qcbin/WTSannouncement.htm”

}

else {

log local0. “all test passed”

set need_cookie0

pool RtpAlmStageAS

}

}

else {

set need_cookie1

log local0. “don’t have a cookie - set cookie is $need_cookie”

HTTP::cookie insert name $cookie value $base_time path “/”

HTTP::redirect “http://almstage.domain.com/qcbin/WTSannouncement.htm”

}

}

elseif { [HTTP::uri] contains “/qcbin”} {

pool RtpAlmStageAS

}

else {

HTTP::redirect “http://almstage.domain.com/qcbin/”

}

}

when HTTP_RESPONSE {

log local0. “http response - $need_cookie”

if { $need_cookie equals 1 } {

log local0. “inserting cookie in response - set cookie is $need_cookie”

HTTP::cookie remove $cookie

HTTP::cookie insert name $cookie value $base_time path “/”

HTTP::cookie expires $cookie 600 relative

HTTP::redirect “http://almstage.domain.com/qcbin/WTSannouncement.htm”

}

}

Thanks,

Dendy

Hi Dendy,

If you want to set a cookie in a redirect you can use HTTP::respond:

http://devcentral.f5.com/wiki/default.aspx/iRules/http__respond

when HTTP_REQUEST {
    set ckname "app"
    set ckvalue "893"
    set cookie [format "%s=%s; path=/; domain=%s" $ckname $ckvalue ".domain.org"]
    HTTP::respond 302 Location "http://www.domain.org" "Set-Cookie" $cookie
}

Aaron

Thanks Aaron… I used your suggestion to make it work. :smiley: