Forum Discussion
Manasi_Sathe_10
Nimbostratus
Dec 15, 2006Reading the host header and directing to the corresponding pool
I want to write a general i-rule for multiple websites such that on reading the url it pools the right pool. for eg:
say i have a couple of url's say 1.abc.xyz.com
2. ptr.xyz.com
and they each have their assosiated pool.. now i want to write a general i-rule that i don't need to update everytime i have a new website..something on the lines of
when HTTP_REQUEST { if { [HTTP::host] matches_regex "*.xyz.com" }{pool *.xyz.com} }
or any ideas how to use switch statements in irules??
Thanks
1 Reply
- hoolio
Cirrostratus
You can check the TCL man pages for details on standard TCL commands:Click here
For F5-specific commands, check the iRules wikiClick here
Try this post to start with: Click here
You could combine that example with this one to set the host to lower case before you make the host header comparison: Click here
Putting those together, here's an example which uses switch with the glob flag (for string comparisons). This is less resource intensive than using a regex to do the comparisons.when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { *example.com - *site1.example.net - *site2* { pool first_pool } *site3* - *site4* { pool second_pool } default { pool default_pool } } }
You can check the iRules wiki page for switch for details on this (Click here)
If you want to debug this, you could add log statements and check the /var/log/ltm log file. Here's an example for logging:
log local0. "client: [IP::client_addr] matched first switch case"
Aaron
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