Forum Discussion

Cri's avatar
Cri
Icon for Nimbostratus rankNimbostratus
Jul 07, 2014

Parsing redirect location uri

Hello team,

 

I've got this kind of problem: I have to complete an APM policy where users, after authentication process, have to be redirected on a specific uri that is defined dinamically in a goto header parameter (i.e. https://www.myvirtual.com/auth?goto=https://www.myvirtual.com/dynamicUri). I'm not sure if it's better to capture goto parameter on HTTP REQUEST event and then use it in a redirect ending, or modify location header on HTTP RESPONSE event. In the first case I used this iRule to capture goto parameter on http request but I'm not able to set a variable that is valid in APM scope:

 

if {[HTTP::uri] starts_with "/auth"} { ACCESS::session data set session.custom.uriGoto [URI::query [HTTP::uri] "goto"] }

 

in the second case I'm not able to parse location uri to capture goto parameter...

 

Any suggestion? Cristian

 

2 Replies

  • Try this:

    when HTTP_REQUEST {
        if { ( [string tolower [HTTP::uri]] starts_with "/auth" ) and ( [ACCESS::policy result] equals "allow" ) } {
            if { [URI::query [HTTP::uri] goto] ne "" } {
                HTTP::redirect [URI::query [HTTP::uri] goto]
            }
        }
    }
    

    This will execute if the URI starts with "/auth" and the access policy evaluation is complete, so it should work in the initial request, and in any request after authentication.

  • Cri's avatar
    Cri
    Icon for Nimbostratus rankNimbostratus

    Thank you Kevin,

     

    this morning I also tried to assign a variable after a landing uri object: session.custom.uriGoto = return [string range [mcget {session.server.landinguri}] 11 end]

     

    and then I used the variable session.custom.uriGoto in a redirect ending and it works well!

     

    Thank you for your help, I'll try your solution too

     

    Cristian