For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

TNY_122436's avatar
TNY_122436
Icon for Nimbostratus rankNimbostratus
Dec 11, 2013

URL Redirect added to existing rule

How can I add another argument so that we can redirect URL's to execute before the code below? For example, I want to have https://domain1.com/nice/main1 to redirect to https://domain1.com/v. Also to have https://domain1.com/nice/main2 redirect to https://domain1.com/y all before the rest of the code below takes place?

 

Code
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
    "/nice*" -
    "/green*" -
    "/tree*" { pool abc }
    default { pool xyz }
}

}

 

5 Replies

  • First keep in mind that a redirect is a physical thing, where the server sends a 30x response to the client with a Location header and a URL for the client to follow. So the client would go to:

    https://domain1.com/nice/main1
    

    Get a redirect response and then go to:

    https://domain1.com/v
    

    And that's what would show up in the browser address bar. Also consider that a redirect is a preemptive thing, so a response is issued immediately to the client and no traffic is passed to any pools. That may or may not be what you want. Also, the stateless nature of HTTP means that one client request for "/nice/main1" and another for "/v", even if from the same client, might as well be from different clients on opposite sides of the planet. That's why you need state mechanisms in HTTP, like cookies. So given that your question involves a redirect to "/v" and then an evaluation of a URI that won't be in the new request, you may need to reconsider what you're attempting to do.

  • It's a matter of "state". So a timeline of events might look like this:

     

    1. Client makes a new request to /nice/main1

       

    2. iRule redirects the user to /v

       

    3. Client makes a new request to /v and both parties are completely oblivious to the previous request. This is really the important part. You could technically set a cookie within the redirect to /v from the first request to /nice, but otherwise the new request to /v is a completely separate and new request with no knowledge of the previous request.

       

    Any URI evaluation that takes requests to a pool must then be based on the final URI (ie. /v).

     

  • Christian_30338's avatar
    Christian_30338
    Historic F5 Account

    Try something like this....(i haven't tested the syntax)

    when HTTP_REQUEST {
       switch -glob [HTTP::uri] {
        "/nice/main1" {
            HTTP::redirect "https://domain1.com/v"
        }
        "/nice/main2" {
            HTTP::redirect "https://domain1.com/y"
        }
        "/nice*" {
            pool abc
        }
        "/green*" {
            pool abc
        }
        default {
            pool xyz
        }
    }
    }
    
  • Agree with Christian. If the third line means anything that starts with /nice but isn't /nice/main1 or /nice/main2, then the above should cover it (a catch all for anything under /nice that isn't otherwise specified). Order of the conditions is of course crucial here.

     

  • Instead of an HTTP::redirect command use the following:

    HTTP::respond 301 Location "https://domain1.com/y"