Forum Discussion

jaddie_85451's avatar
jaddie_85451
Icon for Nimbostratus rankNimbostratus
Jun 26, 2014

Redirect Loop

Hi all

New to iRules and I need help with a redirect here is what I would like to do (11.2.4 HF10)

User goes to existing site www.aaa.com

The user is redirected and presented with an informational page on www.bbb.com/communication; essentially saying that we are upgrading to a new version of software blah, blah

The user would hit continue and go back to www.aaa.com/default and not receive the temp informational page.

I have written a simple redirect but when the user hits continue it is re-executing the existing iRule (as it should) and just looping. Any suggestions or help would be greatly appreciated Thanks

when HTTP_REQUEST {
    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]"
    Check if host header has a value
    if {[HTTP::host] contains "www.aaa.com" } {
                Log redirection
                log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to MWC"
                 Redirect to the requested host and URI
                 HTTP::respond 301 Location "https:// on www.bbb.com/communication "
}
}

6 Replies

  • This is what I might do:

    iRule on site A VIP:

    when HTTP_REQUEST {
        if { [URI::query [HTTP::uri] done] equals "1" } {
            HTTP::respond 302 Location "http://[HTTP::host]/default" "Set-Cookie" "SITEA=1;path=/"
        } elseif { not ( [HTTP::cookie exists SITEA] ) } {
            HTTP::respond 302 Location "http://www.bbb.com/communication"
        } 
    }
    

    Then in your site B link back to site A, add a "done=1" query string:

    [a href="http://www.aaa.com/?done=1"]Click here to continue[/a]
    

    On first request, the URI doesn't contain the done query string and the "SITEA" cookie doesn't exist, so redirect to site B. Clicking the link at site B issues a redirect back site A, which triggers an immediate redirect back to itself and setting the SITEA cookie. All subsequent requests should bypass both conditions.

  • Kevin

     

    Thank you for the fast reply

     

    I apologize if this is a stupid question but the f5 does not own site bbb, so where would I attach

     

    [a href="http://www.aaa.com/?done=1"]Click here to continue[/a]

     

    Is there a good way to use the difference between aaa.com and aaa.com/defaukt

     

    Thanks

     

  • Replace the square brackets in the example with greater-than/less-than signs (the forum will block these tags).

    You might, instead of the query string check, do something like this:

    if { ( [HTTP::uri] equals "/default" ) and not ( [HTTP::cookie exists SITEA] ) }
    
  • Kevin

     

    Thanks again

     

    In what example do I do this

     

    if { ( [HTTP::uri] equals "/default" ) and not ( [HTTP::cookie exists SITEA] ) }

     

    and do I still need to attach this

     

    [a href="http://www.aaa.com/?done=1"]Click here to continue[/a]

     

    Thanks

     

  • First iRule modified:

    when HTTP_REQUEST {
        if { ( [HTTP::uri] equals "/default" ) and not ( [HTTP::cookie exists SITEA] ) } {
            HTTP::respond 302 Location "http://[HTTP::host]/default" "Set-Cookie" "SITEA=1;path=/"
        } elseif { not ( [HTTP::cookie exists SITEA] ) } {
            HTTP::respond 302 Location "http://www.bbb.com/communication"
        } 
    }
    

    And no, you no longer need to modify the HTML link with a query string. So the above basically says:

    1. if the request to site A is for "/default" and the SITEA cookie doesn't exist, redirect to itself and set the SITEA cookie (presumably this request is coming from site B).
    2. Else if the request is not for "/default" and the SITEA cookie doesn't exist, redirect to site B.
    3. And by default, if the request is not for "/default" and the SITEA cookie exists, do nothing (pass the traffic through to site A).
  • Kevin

     

    Thank you so much for your assistance initial testing in our test environment indicates that this is working as desired. I truly appreciate your time and assistance.

     

    Thank you once again.