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

NorCalAdam_6796's avatar
NorCalAdam_6796
Icon for Nimbostratus rankNimbostratus
May 22, 2014

Change part of URI, http port and pool

I am trying to migrate from a version of solr to a multicore version and I need to change the URI and port that comes in. I am wondering how the code below looks:

 

This needs to be changed: http://server.testsub1.testsub.com/solr/select?q=* To this, which hits a different pool: http://server.testsub1.testsub.com:8080/solr/core1/select?q=*

 

when HTTP_REQUEST {

 

Check if path starts with /solr
if { [string tolower [HTTP::path]] starts_with "/solr"}{ 

    Replace /solr with /solr/slszip in the path 
   HTTP::redirect [string map {/solr /core1/slszip} [string tolower [HTTP::path]] ] 
    Redirect port 80 to 8080
   HTTP::redirect http://[getfield [HTTP::host] ":" 1]:8080[HTTP::uri]
   Send to new pool
   pool new_8080_pool
}

}

 

3 Replies

  • Something like this maybe:

    when HTTP_REQUEST {
        if { ( [HTTP::uri] starts_with "/solr" ) and not ( [HTTP::uri] contains "/core1" ) } {
            set uri [string map {"/solr" "/solr/core1"} [HTTP::uri]]
            HTTP::redirect "http://[HTTP::host]$uri"
        } else {
            HTTP::header replace Host "[HTTP::header Host]:8080"
        }
    }
    

    The pool should be assigned to the virtual server, so you don't need to set it in the iRule.

  • So with the if/else statement, it will change it to /solr/core1 and then it will always hit the else so it sends it to 8080? Im unclear if it matches the if statement, makes the change, then exits without hitting the else statement? I need it to always change /solr to /solr/cor1 and the port to 8080.

     

  • If the request URI starts with /solr but does not contain /core1, then it will issue an immediate redirect to the new modified URI. This is a 302 response back to the client telling it to go to a new URL. On the subsequent to /solr/core1, and for any request that contains /core1 in the URI, it'll pass over the if and follow the code in the else condition - which is to add the port number to the end of the Host header. Traffic will flow to the port 8080 pool members by virtue of the pool assigned to the VIP itself.