Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

irule

Bhupendra
Altostratus
Altostratus

I want to put below condition on irule, please help

1. If source IP matches and URI is /A  and /B traffic should be forwarded to POOL A

2. If user is accessing /C-new, rewrite URI to /C and forward to POOL A

3. if not matches 1 and 2 condition defalut POOL B

2 ACCEPTED SOLUTIONS

PeteWhite
F5 Employee
F5 Employee

Maybe think about using a local traffic policy rather than an iRule. It will be more efficient and easier for you to manage

View solution in original post

Hi @Bhupendra , 
As @PeteWhite recommended , yes it's eaiser than iRule and will give you the same result. 

it should be like this : 

Mohamed_Ahmed_Kansoh_0-1687294632129.png

>>> Note that , the last condition "3rd match " should be All Traffic and then do those Actions ( Log and Forward to default pool ) 

This is an overview about Local Traffic policy : 
https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/local-traffic-policies-getting-...

Goodluck

_______________________
Regards
Mohamed Kansoh

View solution in original post

7 REPLIES 7

Hi @Bhupendra , 
in Step 2 of rewrite >>> do you need the source ip matches as well or Not ? 

So you need to match on specific source IP address/address first and then match /A or /B then move traffic to pool A but if the same match on source ip address/addresses but with uri starts with /c-new modify it to be /C and forward traffic to pool A 

if non of those forward to pool B 

that's Correct ? 

 

_______________________
Regards
Mohamed Kansoh

Hi @Mohamed_Ahmed_Kansoh 

 

in Step 2 of rewrite >>> do you need the source ip matches as well or Not ? ------- >>>>No we don't want to match source IP here only URI with any source.

So you need to match on specific source IP address/address first and then match /A or /B then move traffic to pool A but if the same match on source ip address/addresses but with uri starts with /c-new modify it to be /C and forward traffic to pool A 

if non of those forward to pool B
that's Correct ? ----------------->>First condition match on specific source IP address/address first  then match URI /A or /B for selected source IPs then move traffic to pool A

Second condition -any source with uri starts with /c-new modify it to be /C and forward traffic to pool A

If no condition match from 1&2 then default traffic should be route POOL B

Hi @Bhupendra , 

Use this irule : 

when HTTP_REQUEST {
    if { ( [IP::addr [IP::client_addr] equals x.x.x.x ] ) and ( ([HTTP::uri] starts_with "/A") or ([HTTP::uri] starts_with "/B" ) ) }{
        
        log local0. " First Condition matched >>>> GO TO POOL A 🙂 "
        pool POOL_A
        
    } elseif { ( [HTTP::uri] starts_with "/C-new" ) }{
    
     HTTP::uri [string map -nocase {"/C-new " "/C"} [HTTP::uri]]
    
       log local0. " 2nd Condition matched (String MAP did it work ) >>>> GO TO POOL A 🙂 "
       pool POOL_A
       
    } else {
    log local0. " 3rd Condition matched ( Default path ) >>>> GO TO POOL B 🙂 "
    return
    }
}

Don't forget to assign POOL_B as a default pool in Virtual server resources , to forward traffic in case the last condition ( Default ) triggered. 

>> Also Make sure that there are no multiple requests are sent for each web page. 

I mean : 
if you sent req like this http://10.10.10.10/A by the specified source address it should be forwarded correct to pool_A. 
But what if at the same time your web page needs multiple requests like http://10.10.10.10/image.php

so make sure you send only single request per page. 

Goodluck

_______________________
Regards
Mohamed Kansoh

Hi @Bhupendra , 
As @PeteWhite recommended , yes it's eaiser than iRule and will give you the same result. 

it should be like this : 

Mohamed_Ahmed_Kansoh_0-1687294632129.png

>>> Note that , the last condition "3rd match " should be All Traffic and then do those Actions ( Log and Forward to default pool ) 

This is an overview about Local Traffic policy : 
https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/local-traffic-policies-getting-...

Goodluck

_______________________
Regards
Mohamed Kansoh

Hi @Bhupendra , 

Have you tested the irule as well ? 

just test it , you may take it as a reference in further implementations.

Also it will add to me that my code was correct or need further modifications. 

_______________________
Regards
Mohamed Kansoh

That's correct

 

PeteWhite
F5 Employee
F5 Employee

Maybe think about using a local traffic policy rather than an iRule. It will be more efficient and easier for you to manage