Forum Discussion

jmeuse35_166730's avatar
jmeuse35_166730
Icon for Nimbostratus rankNimbostratus
Oct 22, 2014

URL Rewrite - No redirection

A bit new to processing the irules and have a question which I hope the group can asisst with.

 

Scenario: User URL: http://site.company.com/study1

 

F5 will rewrite the URL -> /ServiceStudyDB to the server.

 

Return traffic from the Server will then need to be rewritten back to /study1 for the client. Using the below config, appears to be a redirect loop.

 

when HTTP_REQUEST { Disable the stream filter for client requests if {[HTTP::uri] contains "/study1"}{ HTTP::uri "/ServiceStudyDB" HTTP::header replace Accept-Encoding [string map -nocase {"" "none"} [HTTP::header Accept-Encoding]] STREAM::disable } } when HTTP_RESPONSE { if {[HTTP::header value Server] contains "IIS"}{ set study1_uri [string map -nocase {"/ServiceStudyDB" "/study1"} [HTTP::header "Location"]] HTTP::header replace Location $study1_uri } }

 

The reason for keeping the /studyx is that we will eventually be honing in on this to make sure this gets routed to a specific backend node.

 

19 Replies

  • Seems like there's plenty of over-complication in your current rule. You don't need to overwrite server responses as only the URI was modified. It does not violate cross-domain policy and user browser has no problem with it. Furthermore, it has no awareness the response content did not originate from the originally requested directory.

    The iRule below should cover your needs:

    when HTTP_REQUEST {
    
        if {[HTTP::uri] contains "/study1"} {
          HTTP::header remove "Accept-Encoding"
          HTTP::uri "/ServiceStudyDB"
          STREAM::disable
        }
    }
    
    • jmeuse35_166730's avatar
      jmeuse35_166730
      Icon for Nimbostratus rankNimbostratus
      Thank you for the response and I have tested the simplified iRule. The problem exists when the server has a 302 from within itself to send the requesting URL to /ServicesStudyDB/login.aspx.... Therefore, are "response" rewrite is also required as the requesting browser should only know about /study1. Keep in mind the reason for this is that as we add /study2, /study3, etc.. we will be sending to specific backend nodes and need to keep the URI string on the request in order to send to the correct backend server. Seems the response is the loop. I have this working on the Cisco ACE with some major manipulation and being tasked with getting this to workon on the F5 (which seems possible).
  • Seems like there's plenty of over-complication in your current rule. You don't need to overwrite server responses as only the URI was modified. It does not violate cross-domain policy and user browser has no problem with it. Furthermore, it has no awareness the response content did not originate from the originally requested directory.

    The iRule below should cover your needs:

    when HTTP_REQUEST {
    
        if {[HTTP::uri] contains "/study1"} {
          HTTP::header remove "Accept-Encoding"
          HTTP::uri "/ServiceStudyDB"
          STREAM::disable
        }
    }
    
    • jmeuse35_166730's avatar
      jmeuse35_166730
      Icon for Nimbostratus rankNimbostratus
      Thank you for the response and I have tested the simplified iRule. The problem exists when the server has a 302 from within itself to send the requesting URL to /ServicesStudyDB/login.aspx.... Therefore, are "response" rewrite is also required as the requesting browser should only know about /study1. Keep in mind the reason for this is that as we add /study2, /study3, etc.. we will be sending to specific backend nodes and need to keep the URI string on the request in order to send to the correct backend server. Seems the response is the loop. I have this working on the Cisco ACE with some major manipulation and being tasked with getting this to workon on the F5 (which seems possible).
    • jmeuse35_166730's avatar
      jmeuse35_166730
      Icon for Nimbostratus rankNimbostratus
      As I work through this I think the issue is in the matching for the URI and replacement. Assume the request is: http://site.company.com/study1 and sending to the server as http://site.company.com/ServiceStudyDB. The server is sending back a 302 for ServiceStudyDB/login.aspx. Therefore, I think I need a wildcard that anything after /ServiceStudyDB will continue. ie: Would I not want to make sure that if anything is after the initial replacement that it continues?
    • shaggy_121467's avatar
      shaggy_121467
      Icon for Cumulonimbus rankCumulonimbus
      i'm not sure i understand - are you looking to retain the URI portion after the initial /xxx/? so /ServiceStudyDB/login.aspx would be /study1/login.aspx when it returned to a user?
    • jmeuse35_166730's avatar
      jmeuse35_166730
      Icon for Nimbostratus rankNimbostratus
      That is correct. On a nother platform I can rewrite the URL as "/study1(.*)" and replace with "ServiceStudyDB%1" and vice versa on the response. Sorry to make this confusing, but I believe this is where the redirect is looping.
    • jmeuse35_166730's avatar
      jmeuse35_166730
      Icon for Nimbostratus rankNimbostratus
      As I work through this I think the issue is in the matching for the URI and replacement. Assume the request is: http://site.company.com/study1 and sending to the server as http://site.company.com/ServiceStudyDB. The server is sending back a 302 for ServiceStudyDB/login.aspx. Therefore, I think I need a wildcard that anything after /ServiceStudyDB will continue. ie: Would I not want to make sure that if anything is after the initial replacement that it continues?
    • shaggy's avatar
      shaggy
      Icon for Nimbostratus rankNimbostratus
      i'm not sure i understand - are you looking to retain the URI portion after the initial /xxx/? so /ServiceStudyDB/login.aspx would be /study1/login.aspx when it returned to a user?
    • jmeuse35_166730's avatar
      jmeuse35_166730
      Icon for Nimbostratus rankNimbostratus
      That is correct. On a nother platform I can rewrite the URL as "/study1(.*)" and replace with "ServiceStudyDB%1" and vice versa on the response. Sorry to make this confusing, but I believe this is where the redirect is looping.
  • Here is the solution that works:

    when HTTP_REQUEST {

    if {[HTTP::uri] contains "/study1"} {
      HTTP::header remove "Accept-Encoding"
      HTTP::header replace Location [string map -nocase {"study1" "ServicesStudyDB"} [HTTP::header Location]]
      HTTP::uri "/ServicesStudyDB"
      HTTP::uri [string map -nocase {"study1" "ServicesStudyDB"} [HTTP::uri]]
      STREAM::disable  
    }
    

    } when HTTP_RESPONSE { if {[HTTP::header Content-Type] contains "text"}{

    set study1_uri [string map -nocase {"/ServicesStudyDB" "/study1"} [HTTP::header "Location"]] HTTP::header replace Location $study1_uri
    HTTP::header replace Location [string map -nocase {"ServicesStudyDB" "study1"} [HTTP::header Location]]
      Replace 'old_text' with 'new_text'
    STREAM::expression {@ServicesStudyDB@study1@}
     Enable the stream filter for this response only
    STREAM::enable
    }
    

    }