Forum Discussion
KTrout_49248
Nimbostratus
Apr 16, 2008HTTP redirect to Pools members
How can I create an iRule that will redirect a specific URL to a pool of Web servers hosting the website?
7 Replies
- Kevin_Stewart
Employee
Try this:when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/url1" { pool pool1 } "/url2" { pool pool2 } default { pool pool1 } } }
Kevin - KTrout_49248
Nimbostratus
Again, forgive the stupidity here.
I have a pool of 2 servers calle "web".
What would be the syntax that I would place in the iRule that would load balance to web traffic?
Thanks - Kevin_Stewart
Employee
This is assuming that you have more than one pool of web servers, otherwise configure the virtual server profile to point to a single defined pool on the resources tab.when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/url1" { pool web } "/url2" { pool web2 } default { pool web } } }
"default" should point to whichever pool you want traffic to go to if the uri is different than those defined in the statement. - winifred_corbet
Nimbostratus
Along those same lines, I need to retain the full URI coming in. So, url1/otherfile.html also needs to be directed to pool web, but keep it's full path. Would this rule above still be valid? - winifred_corbet
Nimbostratus
Also, how do I handle someone coming in as http://www.mysite.com/ with no URI, I need a URI of "/" to redirected to correct pool as well. - Kevin_Stewart
Employee
The uri won't be affected by the load balancing, so the server will get the whole thing. There's two ways to catch the base "/", using this structure, that I can think of. Perhaps one of the gurus can confirm this:
1. the "default" case will catch everything not specifically defined, including the "/".
2.when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/url1*" { pool web } "/url2*" { pool web2 } "/" { pool web } default { pool web } } }
I threw the "*" in after the uri in case there's additional text after it. - Nicolas_Menant
Employee
if you have a lots of different uri to filter you should have a look at creating class with the findclass commands: Click here
Usually using a class is more eficient when you have more than 100 different data to filter
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects