iRule - URL Redirect

Hello,

One of our sites has two virtual servers, one for port 80 and another for 443. The port 80 virtual server currently has a https redirect iRule attached sending all port 80 traffic to 443. The business is asking if I can do a couple of url redirects. For example, sending all www.123.com/games requests to www.123.com/test1 and all www.123.com/live to www.123.com/test2. Can you please provide an iRule I can use to fulfill this request? Can I use just one iRule to do multiple url redirects? and where do I attach the iRule? on the port 443 virtual server.

Thank you for your help!

Yes you can do this with one iRule. It could look something like this:

when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::path]] {
        "/games*" {
            HTTP::respond 301 noserver Location "https://[HTTP::host]/test1"
        }
        "/live*" {
            HTTP::respond 301 noserver Location "https://[HTTP::host]/test2"
        }
        default {
            return
        }
    }
}

Also, if you are using BigIP v11.4+ you can also consider using Local Traffic Policies to redirect traffic based on HTTP::path.

Hello,

Thank you for your reply! I have applied the above iRule and it appears to be working.

Thank you again for your help.