Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Need help with irule

Looking for feedback on irule for redirect. I am a network engineer who had our loadbalancers dumped in my lap and a request for an irule to be placed.

Not familiar at all with how to do this but I hope I am on the right track. "https://server-fiver.domain.com/index"; those requests need to only go to one server "https://srv-one-games001-test/location/"; I want the rest of the traffic that normally is served by the server to be balanced across the pool as normal.

From all my research it should look like this? And all I need to do is put it under the irules section under local traffic correct?

    when HTTP_REQUEST {
if
{ [HTTP::uri] equals "https://server-fiver.domain.com/index" }
{ HTTP::redirect "https://srv-one-games001-test/location/" }
}

Thank you ahead of time!

0
Rate this Question
Comments on this Question
Comment made 18-Jul-2017 by Heinrichm 123

When you say you want it to only go to one server;
a. Not go through F5, F5 only redirects the client to the actual server
b. Still go through F5, but F5 only sends the traffic to a specific server

I know that you've written it as scenario a, but I've talked with too many who actually meant b. I can also see that PK and Andrew are solving the question two different ways; b and a respectively.

0
Comment made 18-Jul-2017 by Jacob Kinkade 1

I have a pool of servers. The developers hosted something on one of these servers and asked that a rule be created that sends requests for those assets straight to that directory, with all other requests for other assets to be balanced across the pool as normal. So situation b. Sorry for not being as clear when I wrote it, it was a long night.

0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hope this work..

  1. Create this irule under Local traffic --> iRules
  2. Apply it to your virtual server under Local Traffic --> Virtual servers and once you are in the virtual server properties page, click Resources tab from top, add the irule you created in iRule section.

when HTTP_REQUEST {
if { string tolower [HTTP::uri] equals "/index" } {
HTTP::uri "/location"
node Insert_IPaddress_Of_srv-one-games001-test Port#_of_srv-one-games001-test
##Example: node 10.10.10.10 8080
}
else {
Default_pool //Change this to your default pool name
}
}

0
Comments on this Answer
Comment made 17-Jul-2017 by Jacob Kinkade 1

Thanks a ton! I will be test this out tonight! I have some scotch that needs drinking after this night!

0
Comment made 17-Jul-2017 by PK 628

you will.. :) Good luck!

0
Comment made 17-Jul-2017 by Jacob Kinkade 1

All ready to set it up, just a dumb question though.

else {
pool_1 //Change this to your default pool name
}
}

or

   else {
Default_pool //pool_1
}

Thanks a ton for your help sir!

0
Comment made 17-Jul-2017 by Andrew Husking 693

You need two } at the end, one to close the else, one to close the when HTTP_REQUEST

If all you need to do is redirect /index to another server then i'd use the following code

when HTTP_REQUEST {
    if { [string tolower [HTTP::uri]] equals "/index" } { 
        HTTP::redirect "https://srv-one-games001-test/location/" 
    }  
}

HTH Andrew

0
Comment made 17-Jul-2017 by Jacob Kinkade 1

The urls are actually HTTPS, should I just use HTTPS instead of HTTP?

0
Comment made 17-Jul-2017 by Andrew Husking 693

Yup

0
Comment made 17-Jul-2017 by Jacob Kinkade 1

Getting an error when trying that 01070151 unknown

`when HTTPS_REQUEST {

if { [string tolower [HTTPS::uri]] equals "/index" } {
         HTTPS::redirect "https://srv-one-games001-test/location/"
  }  
}
0
Comment made 17-Jul-2017 by Andrew Husking 693

Sorry it's supposed to be when HTTP_REQUEST {

0
Comment made 17-Jul-2017 by Jacob Kinkade 1
when HTTPS_REQUEST {
    if { [string tolower [HTTPS::uri]] equals "/index" } { 
        HTTPS::redirect "https://srv-one-games001-test/location/" 
    }  
}

Is what I currently have. I appreciate the help

0
Comment made 17-Jul-2017 by Andrew Husking 693

Try

when HTTP_REQUEST { if { [string tolower [HTTP::uri]] equals "/index" } { HTTP::redirect "https://srv-one-games001-test/location/"; }
}

0
Comment made 17-Jul-2017 by Jacob Kinkade 1

Ok awesome. I appreciate the help, I will be able to test it when the devs come in this morning.

0
Comment made 18-Jul-2017 by PK 628

its..
else {
pool pool_1
}
}
here pool_1 is your default pool

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

I haven't tested this iRule but given the conditions I'd go for

when HTTP_REQUEST {
# redirects the client to the correct catalogue
if { ([string tolower [HTTP::host]] equals "server-fiver.domain.com") && ([string tolower [HTTP::uri]] == "/index") }{
    HTTP::redirect https://[HTTP::host]/location/
    }
# send the client to the server when requesting this catalogue
if { [string tolower [HTTP::uri]] starts_with "/location/" } {
    pool my_pool member srv-one-games001-test 443
    }
}

If there's only one domain for the VIP it is not necessary to have both conditions in the first if statement.

0