irule which check if uri contains services

I need a irule which check if uri contains services like http://domain.name.com/services" or “oservices” then send traffic to service_pool or oservice_pool but before that it should change uri to /wps/portal instead of /services or /oservices

You should assign something like the following iRule to your virtual server:

when HTTP_REQUEST {
    if { [HTTP::uri] contains "services" } {
        HTTP::redirect "/wps/portal"
        pool SERVICE_POOL
    }
    elseif { [HTTP::uri] contains "oservices" } {
        HTTP::redirect "/wps/portal"
        pool OSERVICE_POOL
    }
}

Thanks. I tried but it is sending traffic to default pool not to member of service_pool

You can add some logging to your irule to make sure that conditions in if statement work fine. And then look in /var/log/ltm for your messages. Like this: when HTTP_REQUEST { log local0. “URI = [HTTP::uri]” if { [HTTP::uri] contains “services” } { HTTP::redirect “/wps/portal” pool SERVICE_POOL log local0. “SERVICE POOL” } elseif { [HTTP::uri] contains “oservices” } { HTTP::redirect “/wps/portal” pool OSERVICE_POOL log local0. “OSERVICE_POOL” } }

I added log local0 but nothing appearing in /var/log/ltm

Even the string with URI? log local0. “URI = [HTTP::uri]” - this should work on every HTTP Request. Are you sure you have assigned this iRule to virtual server?

sorry i found log it says below. why request /wps/portal is not going to member of SERVICE POOL Apr 10 11:26:01 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : URI = /services Apr 10 11:26:01 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : SERVICE POOL Apr 10 11:26:01 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : URI = /wps/portal

I see. The problem is that we shouldn’t use redirect here. Then iRule should be the following: when HTTP_REQUEST { log local0. “URI = [HTTP::uri]” if { [HTTP::uri] contains “services” } { HTTP::uri “/wps/portal” pool SERVICE_POOL log local0. “SERVICE POOL” } elseif { [HTTP::uri] contains “oservices” } { HTTP::uri “/wps/portal” pool OSERVICE_POOL log local0. “OSERVICE_POOL” } }

Thanks but still same problem Apr 10 11:41:56 CIODCDMZF5LTM02 info tmm7[10306]: Rule /Common/services.portal : URI = /services Apr 10 11:41:56 CIODCDMZF5LTM02 info tmm7[10306]: Rule /Common/services.portal : tstsrv_Pool_http Apr 10 11:41:56 CIODCDMZF5LTM02 info tmm7[10306]: Rule /Common/services.portal : URI = /wps/portal/!ut/p/a1/04_Sj9CPykssy0xPLMnMz0vMAfGjzOItLNydDY0sjLzcTcOMDBxNLE0sLcNMjQwMTIEKIoEKDHAARwNC-sP1o8BKnN0dPUzMfYB6TCyMDDxdnDxczC19DQw8zaAK8FhRkBthkOmoqAgAqk60hg!!/dl5/d5/L2dBISEvZ0FBIS9nQSEh/

Hm, this is strange. Try this one, let’s see what’s going wrong: when HTTP_REQUEST { log local0. “URI = [HTTP::uri]” if { [HTTP::uri] contains “services” } { log local0. “URI CONTAINS SERVICES” HTTP::uri “/wps/portal” pool SERVICE_POOL log local0. “SERVICE POOL” } elseif { [HTTP::uri] contains “oservices” } { log local0. “URI CONTAINS OSERVICES” HTTP::uri “/wps/portal” pool OSERVICE_POOL log local0. “OSERVICE_POOL” } else { log local0. “DEFAULT POOL” } }

Thanks again after change below are log Apr 10 12:41:39 CIODCDMZF5LTM02 info tmm7[10306]: Rule /Common/services.portal : URI = /services Apr 10 12:41:39 CIODCDMZF5LTM02 info tmm7[10306]: Rule /Common/services.portal : URI CONTAINS SERVICES Apr 10 12:41:39 CIODCDMZF5LTM02 info tmm7[10306]: Rule /Common/services.portal : SERVICE POOL

So, I suppose it should work. Is it not?

nopes. it is going default pool Apr 10 12:48:27 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : URI = / Apr 10 12:48:27 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : DEFAULT POOL Apr 10 12:48:37 CIODCDMZF5LTM02 info tmm1[10306]: Rule /Common/services.portal : URI = /services Apr 10 12:48:37 CIODCDMZF5LTM02 info tmm1[10306]: Rule /Common/services.portal : URI CONTAINS SERVICES Apr 10 12:48:37 CIODCDMZF5LTM02 info tmm1[10306]: Rule /Common/services.portal : SERVICE POOL Apr 10 12:48:45 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : URI = /wps/portal/!ut/p/a1/04_Sj9CPykssy0xPLMnMz0vMAfGjzOI9_A3MDI0sjLz8g90sDBwtwnzdnSzdjA3cjYEKIoEKDHAARwNC-sP1o8BKDIx8nQ09TYy8DHx9gfosnIJ8QtycDQwsjAgoAJoBVYDbDQW5EQaZno6KAIdXbvQ!/dl5/d5/L2dBISEvZ0FBIS9nQSEh/ Apr 10 12:48:45 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : DEFAULT POOL Apr 10 12:48:45 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : URI = /wps/portal/!ut/p/a1/04_Sj9CPykssy0xPLMnMz0vMAfGjzOI9_A3MDI0sjLz8g90sDBwtwnzdnSzdjA3cjYEKIoEKDHAARwNC-sP1o8BKDIx8nQ09TYy8DHx9gfosnIJ8QtycDQwsjAgoAJoBVYDbDQW5EQaZno6KAIdXbvQ!/dl5/d5/L2dBISEvZ0FBIS9nQSEh/ Apr 10 12:48:45 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : DEFAULT POOL Apr 10 12:48:45 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : URI = /wps/portal/!ut/p/a1/04_Sj9CPykssy0xPLMnMz0vMAfGjzOI9_A3MDI0sjLz8g90sDBwtwnzdnSzdjA3cjYEKIoEKDHAARwNC-sP1o8BKDIx8nQ09TYy8DHx9gfosnIJ8QtycDQwsjAgoAJoBVYDbDQW5EQaZno6KAIdXbvQ!/dl5/d5/L2dBISEvZ0FBIS9nQSEh/ Apr 10 12:48:45 CIODCDMZF5LTM02 info tmm2[10306]: Rule /Common/services.portal : DEFAULT POOL

Let’s try persistence: when HTTP_REQUEST { log local0. “URI = [HTTP::uri]” if { [HTTP::uri] contains “services” } { log local0. “URI CONTAINS SERVICES” HTTP::uri “/wps/portal” pool SERVICE_POOL persist cookie insert “service_persistence” log local0. “SERVICE POOL” } elseif { [HTTP::uri] contains “oservices” } { log local0. “URI CONTAINS OSERVICES” HTTP::uri “/wps/portal” pool OSERVICE_POOL persist cookie insert “oservice_persistence” log local0. “OSERVICE_POOL” } }

Now i made it very simple. log is printing pool name but request are going to default pool. Please help when HTTP_REQUEST { if { [HTTP::uri] contains “services” } { log local0. “URI CONTAINS SERVICES” HTTP::uri “/wps/portal” pool tstsrv_Pool_http log local0. “SERVICE POOL” } } log print Apr 11 14:28:46 CIODCDMZF5LTM02 info tmm1[10306]: Rule /Common/service.portal.redirect : URI CONTAINS SERVICES Apr 11 14:28:46 CIODCDMZF5LTM02 info tmm1[10306]: Rule /Common/service.portal.redirect : SERVICE POOL

You need to configure persistence as I wrote above: if { [HTTP::uri] contains “services” } { log local0. “URI CONTAINS SERVICES” HTTP::uri “/wps/portal” pool SERVICE_POOL persist cookie insert “service_persistence” log local0. “SERVICE POOL” }

only adding this line persist cookie insert “service_persistence” or i need configure profile?

i tried by adding this line but request is not going pool. it is going default pool node member as i see it try find Not Found The requested URL /services was not found on this server. -------------------------------------------------------------------------------- IBM_HTTP_Server at tstprl.bahrain.bh Port 80

some on virtual server is not allowing to go to another pool. i also tried to send request directly to node 192.168.190.3 80 but always go to default pool node member and log shows pr 11 15:20:13 CIODCDMZF5LTM02 info tmm3[30531]: Rule /Common/service.portal.redirect : URI CONTAINS SERVICES Apr 11 15:20:13 CIODCDMZF5LTM02 info tmm3[30531]: Rule /Common/service.portal.redirect : SERVICE POOL

i tried this as well but no result when HTTP_REQUEST { if { [HTTP::uri] contains “services” } { log local0. “URI CONTAINS SERVICES” node 192.168.190.3%1 80 persist cookie insert “service_persistence” log local0. “SERVICE POOL” } }