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

Wilson_Stuart's avatar
Wilson_Stuart
Icon for Nimbostratus rankNimbostratus
Mar 13, 2017

URI based 301 redirection to alternate Virtual Server

I am a novice when it comes to working with iRules, and I have a need to redirect incoming http requests from the default virtual-server to an alternate VS only if the contents of the uri match a certain criteria, and maintain the uri while the host is redirected. I am asking for syntax checking to see if the iRule I have built will work for what I am needing.

The default vip the requests would be coming in on as an example would be ";.

when HTTP_REQUEST {

if { [HTTP::path] starts_with "/~blahcomm" } {
    HTTP::respond 301 Location "http://vipweb.prod.blah.com[HTTP::path]"
}
elsif { [HTTP::path] starts_with "/blahwide" } {
    HTTP::respond 301 Location "http://vipweb.prod.blah.com[HTTP::path]"
}

}

2 Replies

  • It looks fine :) However since both "if" do the same thing, you could group them together. Ex :

     

    if { (HTTP::path] ...) or (HTTP::path] ...) }

     

    But otherwise it should work. You can also replace [HTTP::path] by [HTTP::uri] in the redirection if you also wish to keep the query string.

     

  • This gives you the difference between HTTP::path, HTTP::uri, HTTP::query.

     

    You can use "OR" statement as stated by Stephane.