Select pool based on HTTP host header

Problem this snippet solves:

This rule was designed for a customer that had many websites hosted on one VIP. This rule will dynamically assign a pool name based on the host header sent. In this case, the admin will only have to add a pool named, for example, www.test.com_pool instead of adding every possible host header value to a switch or if/then statement in the Irule.

Code :

    set hostpool [string tolower [HTTP::host]]_pool
    # Show us what the client sent in the host header - Turn this OFF in production
    log local0. "pool is $hostpool"
    # Use if/then with "Catch" to account for any bad host headers - otherwise TCL will throw an error to the client
    if { [catch {pool $hostpool} exc] } {
        # If a client sends a host header that does not match a pool, send to default pool
        pool P3
Published Mar 18, 2015
Version 1.0

Was this article helpful?