Forum Discussion
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
- Kevin_Stewart
Employee
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.
- NorCalAdam_6796
Nimbostratus
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.
- Kevin_Stewart
Employee
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.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com