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

cymru81's avatar
cymru81
Icon for Altocumulus rankAltocumulus
Nov 18, 2015

iRule redirect help!

Hi, im looking to create an iRule to do some redirects depending on url requested. I think i have it working but am concerned about the case eg small 'a' or big 'A' as the redirect doesnt work if its different. Does this look correct and is there and easier way i could do this too?

when HTTP_REQUEST {

if {[HTTP::path] eq "/"}{

  HTTP::redirect "http://[HTTP::host]/home/live"

} if {[HTTP::path] eq "/a"}{

  HTTP::redirect "http://[HTTP::host]/a/"

} if {[HTTP::path] eq "/testinst"}{

  HTTP::redirect "http://[HTTP::host]/testinst/"

}

}

Thanks!

3 Replies

  • If you were going to use an iRule, I'd suggest something like this. (You can use

    [string tolower XXX]
    to get the lowercase version of a string.

    when HTTP_REQUEST {
        switch [string tolower [HTTP::path]] {
            "/" {
                HTTP::redirect "http://[HTTP::host]/home/live"
            }
            "/a" {
                HTTP::redirect "http://[HTTP::host]/a/"
            }
            "/testinst" {
                HTTP::redirect "http://[HTTP::host]/testinst/"
            }
            default {
            }
        }
    }
    

    If you're running 11.4 or later, you could also consider using a Local Traffic Policy instead since this would be a simple rule. (Here's a link on how to create a redirect). Because they're built into the core, local traffic policies are a little more efficient than an iRule.

  • thats perfect, thank you!

     

    one more quick question! is there any way to hide the / part of the address when it redirects etc. so all teh user sees is www.domain.com if that makes sense too?

     

  • thats fine,was just a thought!

     

    thank you again for your help.