Forum Discussion

neeraj_66310's avatar
neeraj_66310
Icon for Nimbostratus rankNimbostratus
Dec 13, 2007

I need to remove host from url and send it to particular pool

I am novice for creating irule, Kindly help me out for below requirement:--

 

 

user make request for one of 3 urls as below:--

 

1)http://main.test.com

 

2)http://main.test.com/first.test.com

 

3)http://main.test.com/second.test.com

 

 

We need to create irule to fulfill below 3 requiremnent using one Irule:--

 

1)If uri contain first.test.com, then Big IP LTM should remove main.test.com from url i.e. make it

 

http://first.test.com and send request to pool_first(pool name)

 

 

2)If uri contain second.test.com, then Big IP LTM should remove main.test.com from url i.e. make it

 

http://second.test.com and send request to pool_second

 

(pool name)

 

 

3)else (otherwise) it should send request to poolmain

 

(pool name)

10 Replies

  • You have left out a few details. What would you like done to the rest of the uri's (if they are present).

    For example, how would you like this routed?

    http://main.test.com/first.test.com/foo/bar

    Would you want the rest of the URI (/foo/bar) stripped off and just change the host header ot first.test.com and send a blank URI ("/")? If so, this should do what you want.

    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::uri]] {
        "/first.test.com*" {
          HTTP::header replace "Host" "first.test.com"
          HTTP::uri "/"
          pool pool_first
        }
        "/second.test.com*" {
          HTTP::header replace "Host" "second.test.com"
          HTTP::uri "/"
          pool pool_second
        }
        default {
          pool poolmain
        }
      }
    }

    You may need to change the "HTTP::uri" assignment lines depending on what you want to do with the URI's. You could omit it and it would send the original URI's on to the server, you could keep it as-is and it will send an empty URI ("/"), or you could do some string mapping to remove the host value from the URI and send whatever originally in it.

    Hopefully this gives you something to run with...

    -Joe
  • Dear Joe,

     

    Thanks for your help. Sorry ,as I have not described the requirement exactly.

     

    let me describe the requirement in details as below:--

     

     

    user make request for one of 3 urls as below:--

     

    1)http://main.test.com/abc/jhk

     

    2)http://main.test.com/first.test.com/jui/yui/opi

     

    3)http://main.test.com/second.test.com/juy/lok.kip

     

     

    We need to create irule to fulfill below 3 requiremnent using one Irule:--

     

    1)If uri contain first.test.com, then Big IP LTM should remove main.test.com from url i.e. make it

     

    http://first.test.com//jui/yui/opi and send request to pool_first(pool name)

     

     

    2)If uri contain second.test.com, then Big IP LTM should remove main.test.com from url i.e. make it

     

    http://second.test.com/juy/lok.kip and send request to pool_second

     

    (pool name)

     

     

    3)else (otherwise) it should send request to poolmain

     

    (pool name)

     

     

    I think irule suggested by you is stripping everything after fist.test.comin in 2) option and stripping everything after second.test.com in 3) option.

     

     

    Kindly modify the Irule for described request.

     

     

    Thanks
  • Dear Joe,

     

     

    I mean to remove the host value from the URI and send whatever originally in it.

     

    Kindly modify the irule sent by you to fulfill the requirement sent in my second reply, as it is very much complex for me.

     

     

     

  • Dear Joe,

     

     

    As you asked right clarification i.e.

     

    You have left out a few details. What would you like done to the rest of the uri's (if they are present).

     

     

    For example, how would you like this routed?

     

     

    As I have mentioned in my second reply they should be sent as they are as I clarified that in my second mail.

     

    Kindly help me out.
  • Dear joe,

     

    I do not want the rest of the URI to be (/foo/bar) stripped off , it should remain as it is. i.e. I want /foo/bar as it is.

     

    How to do it?
  • Dear joe,

     

    I do not want the rest of the URI to be (/foo/bar) stripped off , it should remain as it is.

     

    For option 2) and 3) the rest of uri what you mentioned as /foo/bar portion will keep on changing and that should be send as original to server.i.e. I need /foo/bar as it is.

     

    My problem is that I canot specify uri must be some fix value, as it will keep on changing if we browse within that page, only first.test.com portion will remain same for example 1)

     

     

     

    I am giving example:--

     

     

    user can request :--

     

     

    a)http://main.test.com/first.test.com/jui/yui/opi

     

    b)http://main.test.com/first.test.com/diff/one/two

     

    c)http://main.test.com/first.test.com/diff/one/two

     

    so on.

     

     

    I need that big ip should do neccessary changes and send this user requests to server as below:--

     

    a)http://first.test.com/jui/yui/opi

     

    b)http://first.test.com/diff/one/two

     

    c)http://first.test.com/diff/one/two

     

    respectively

     

     

    I tested your irule, now it is sending the request by replacing main.test.com as first.test.com as below:--

     

    http://first.test.com/first.test.com/jui/yui/opi

     

    which is not correct it should be :--

     

    http://first.test.com/jui/yui/opi

     

     

    To solve above problem, I tried with keeping replace "host" value blank but in this case big ip sends request as below:--

     

    http:///first.test.com/diff/one/two

     

    above you can see, after http: 3 forward slash are coming.

     

     

    Other option which I can not use is specify uri exactly as only first.test.com portion of uri is same but later portion of uri keeps on changing.

     

     

    I am near to get solution by using your solution, only problem is that, we need to modify Irule suggested by you so that bigip will replace the host as suggested in irule and will remove only first.test.com portion of uri and rest it will send as it is.

     

     

    I think now problem is very much clear.

     

     

    Kindly provide me the solution if it is not possible to do it on Big ip let me know.

     

     

    Waiting for your valuable suggestion.

     

     

    Thanks

     

     

     

     

  • Glad to be of help. Just to let you know that we are not consulting here at DevCentral and would like to see our users put some effort in writing the iRules themselves to help you all be more self-sufficient. We are here to help out debugging and giving you guidance (and occasionally write functional iRules when the need arises).

     

     

    I know this is hard for someone who is new to the technology and we do our best to help out in these situations so hopefully my first stab got you going in the right direction. I'd really like you to try to do this yourself. I'll line out what and how you need to do it and then you can give it a try. After you do and you are still having issues, please post your iRule and we'll work through it together. This way you, as well as the rest of the community, will benefit.

     

     

    Take my above iRule:

     

     

    
    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::uri]] {
        "/first.test.com*" {
          HTTP::header replace "Host" "first.test.com"
          HTTP::uri "/"
          pool pool_first
        }
        "/second.test.com*" {
          HTTP::header replace "Host" "second.test.com"
          HTTP::uri "/"
          pool pool_second
        }
        default {
          pool poolmain
        }
      }
    }

     

     

    The conditional testing is there already which you have determined is correct. In this code, I've replace the "Host" header with the pulled out values from the URIs and you've said that part is correct. So, the last part is removing the new host value from the URI. You can easily do this with the "string map" command.

     

     

    Here's an example of replacing a string with string map:

     

     

    set orig "/one/two/three/four"
    set stripped [string map { "/two" "" } $orig]

     

     

    In the above code the value of the $stripped variable will contain the value of $orig with all matches of "/two" replaced with "" (essentially removing it from the string). The value of $stripped will be "/one/three/four"

     

     

    Taking this in your example, you'll what to do something like this for each of your matched cases

     

     

    HTTP::uri [string map { "somval" "" } [HTTP::uri]]

     

     

    Replace "someval" with the string you want to remove and this command will use the assignment version of the HTTP::uri command and assign it the value of the HTTP URI with "someval" stripped. In your case use "/first.test.com", "second.test.com", etc.

     

     

    Give this a shot and post back when you've fixed the iRule and it still doesn't seem to be working.

     

     

    Cheers!

     

     

    -Joe
  • Thanks Joe,

     

     

    From your reply I have created irule as below:--

     

     

    when HTTP_REQUEST {

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/first.test.com*" { HTTP::header replace "Host" "first.test.com"

     

    HTTP::uri [string map { "first.test.com" "" } [HTTP::uri]]

     

    pool pool_first }

     

    "/second.test.com*" {

     

    HTTP::header replace "Host" "second.test.com"

     

    HTTP::uri [string map { "second.test.com" "" } [HTTP::uri]]

     

    pool pool_second

     

    }

     

    default {

     

    pool poolmain

     

    }

     

    }

     

    }

     

     

     

     

    I have modified your previous irule according to your suggestion.I think it should work.

     

    The whole scenario is for load balancing.Sap portal access.

     

     

    But I was not able to test above Irule, as now we are testing scenario in differenct way.In which case, host need not be replaced and also uri rewriting is not required.

     

    Only port is changed by stream profile so server response to user make request on port 8001 changed to request on 80 port to first.test.com.

     

    And in host entries we map all three FQDN (main.test.com, first.test.com and second.test.com) to same Ip address, which is Big ip Virtual server ip address. Here we are successfull in getting the second page but we are not able to get images(jpg)(page content), there we are getting red cross symbol.

     

    We are assuming that this problems reason is, as SAP server is already sending image file in compressed format, so Big IP box is not able to understand that.

     

     

    If I come to some solution, I will let you know, as that could be usefull to other Forum peoples who may face this type of problem.

     

    Secondly if I ever test our scenario with your suggested irule, I will definitely reply whether it has worked or not(that irule I already shown above only I have not tested it yet)

     

     

    Joe thanks again for your valuable irule, and your suggestion on further modifying it according to scenario.

     

    Thanks.

     

     

  • No problem. Please feel free to post again if anything comes up.

     

     

    -Joe