Forum Discussion

adrian_171483's avatar
Oct 06, 2016
Solved

Irule to "prepend" directory and retain URI

Hi. i have a requirement for the following:

 

type somesite.com/anything/anything

 

then we need to add /something into the URI without a redirect and retain the original client URI request

 

so the request to the server becomes:

 

somesite.com/something/anything/anything

 

it would be nice to see this back on the client browser if possible but cant have a re-direct

 

  • when HTTP_REQUEST {
        HTTP::header replace Host "[HTTP::host]:38080"
        log local0. "Sending request to server"
        Log the original path if debug is enabled
       if {$::uri_mapping_debug}{log local0. "Original path: [HTTP::host][HTTP::uri]"}
    
        If the path doesn't already start with the base URI and version, insert it
       if {[string tolower [HTTP::path]] starts_with "/api/"}{
          HTTP::path "/imr-ce-web[HTTP::path]"
    
           Log the modified path if debug is enabled
          if {$::uri_mapping_debug}{log local0. "Modified path: path: [HTTP::host][HTTP::uri]"}
       }
    }
    

4 Replies

  • Here's a link to an iRule that should accomplish what you are trying to do, other than the behavior below.

     

    it would be nice to see this back on the client browser if possible but cant have a re-direct

     

    I don't think this latter point is going to be possible.

     

  • so the Irule is not modifying the path for some reason ??

    when RULE_INIT {

    The base of the URI set ::uri_base "/mystring/"

    Enable/disable debug logging to /var/log/ltm set ::uri_mapping_debug 1 }

    when HTTP_REQUEST { Log the original path if debug is enabled if {$::uri_mapping_debug}{log local0. "Original path: [HTTP::path]"}

    If the path doesn't already start with the base URI and version, insert it if {not ([string tolower [HTTP::path]] starts_with "$::uri_base$::version_string")}{ HTTP::path [string map [list $::uri_base] [HTTP::path]]

       Log the modified path if debug is enabled
      if {$::uri_mapping_debug}{log local0. "Modified path: [string map [list $::uri_base "$::uri_base$::version_string/"] [HTTP::path]]"}
    

    } }

    Thu Nov 3 19:38:07 GMT 2016 info xxx tmm[14206] Rule /Common/PREPEND-DEV-TEST : Original path: /api/1/claimrefs Thu Nov 3 19:38:07 GMT 2016 info xxx tmm[14206] Rule /Common/PREPEND-DEV-TEST : Modified path: /api/1/claimrefs

    • adrian_171483's avatar
      adrian_171483
      Icon for Cirrus rankCirrus

      So i have cracked it,

          when HTTP_REQUEST {
          HTTP::header replace Host "[HTTP::host]:38080"
          log local0. "Sending request to server"
          Log the original path if debug is enabled
         if {$::uri_mapping_debug}{log local0. "Original path: [HTTP::host][HTTP::uri]"}
      
          If the path always starts with /api/ prepend the uri with /something
         if {[string tolower [HTTP::path]] starts_with "/api/"}{
            HTTP::path "/something[HTTP::path]"
      
             Log the modified path if debug is enabled
            if {$::uri_mapping_debug}{log local0. "Modified path: path: [HTTP::host][HTTP::uri]"}
         }
      }
      
  • when HTTP_REQUEST {
        HTTP::header replace Host "[HTTP::host]:38080"
        log local0. "Sending request to server"
        Log the original path if debug is enabled
       if {$::uri_mapping_debug}{log local0. "Original path: [HTTP::host][HTTP::uri]"}
    
        If the path doesn't already start with the base URI and version, insert it
       if {[string tolower [HTTP::path]] starts_with "/api/"}{
          HTTP::path "/imr-ce-web[HTTP::path]"
    
           Log the modified path if debug is enabled
          if {$::uri_mapping_debug}{log local0. "Modified path: path: [HTTP::host][HTTP::uri]"}
       }
    }