Forum Discussion

Deepak_Nair's avatar
Feb 18, 2021

Need a HELP with my IRULE

Hi Folks ,

 

I am working on one requirement and need a little help with my Irule .

 

 

When CLIENT makes a req with https://example.com/abcserver and hit to F5 , the F5 should send a response as https://example.com/abcserver/rest/services . I am able to achieve this part through re-direction ( But i am not sure if this is the correct way of doing this ) .

 

 

After that the F5 should do a GET request to backend server as below :

 

GET xyz or GET xyz/rest/services to the backend server

 

 

I have written this irule , re-direction is working BUT not able to GET the content .

 

if {([string tolower [HTTP::host]] equals "example.com") && [HTTP::uri] starts_with "/abcserver" } {

 

 HTTP::redirect "https://example.com/abcserver/rest/services

  

 }

  

if {([string tolower [HTTP::host]] equals "example.com") && [HTTP::uri] starts_with "/abcserver" } {

 

 HTTP::uri [string map [list "/abcserver" ""] xyz/[HTTP::uri]]

  

     node 1.1.1.1 6443

  

}

 

I think my this irule ends up in too many re-direction . I am NOT able to understand how to achieve the GET part through irule once re-direction is DONE.

 

 

IS this the right way of doing this through re-direction .

 

Any help in this regard is greatly appreciated .

 

Thanks .

3 Replies

  • Ok , i tweak by irule and able to load the page , BUT response to CLIENT is not what is expected . i have removed the redirect statement under the irule .

     

    This is how my irule looks now .

     

    when HTTP_REQUEST { 

     

      

    if {([string tolower [HTTP::host]] equals "example.com") && [HTTP::uri] starts_with "/abcserver" } {

      

      HTTP::uri "/xyz/rest/services"

          node 1.1.1.1 6443

        

      

    }

     

    }

     

    The CLIENT is expected to see in the browser https://example.com/abcserver/rest/services

     

    when request is made with https://example.com/abcserver

     

    i am not able to achieve this . Any help in this regard greatly appreciated .

     

    Thanks

  • I see you are using starts_with, which will match all time. Try equals.

    if {([string tolower [HTTP::host]] equals "example.com") && [HTTP::uri] equals "/abcserver" } {
    HTTP::redirect "https://example.com/abcserver/rest/services" 
    }
    if {([string tolower [HTTP::host]] equals "example.com") && [HTTP::uri] equals "/abcserver/rest/services" } {
    HTTP::uri [string map {"/abcserver" "/xyz"} [HTTP::uri]]
    node 1.1.1.1 6443
    }

    So once its redirected, the request is going to come in with /abcserver/rest/services, then on the second condition you can make that check & modify your GET request.