Forum Discussion

Ankur_5273's avatar
Ankur_5273
Icon for Nimbostratus rankNimbostratus
Jun 12, 2014
Solved

Rewrite the content in URI with a short URL

Hi Experts

 

I need assistance on shortening of URL as follows

 

If a web page with following Source URL is browsed , then a part of URI (highlighted in bold) should be converted to "en" (which is English language ) and output should be Masked URL as shown below .

 

Source URL : http://hostname/secureapp/connect/report_en/REP/XYZ

 

Masked URL : http://hostname/en/XYZ

 

Regards, Ankur

 

  • I am unable to update my original post. Here is an updated version.

    If you simply want to mask URL's then apply a STREAM profile with the following iRule.

    when HTTP_REQUEST {
      log local0. "..in HTTP_REQUEST"
    
       no replacement for requests
      STREAM::disable
       disable compression server side
      HTTP::header remove "Accept-Encoding"
    }
    when HTTP_RESPONSE {
      log local0. "...in HTTP_RESPONSE"
    
       only replace text content
      if {!([HTTP::header value Content-Type] contains "text")}{ return}
    
      set search ""
      foreach pair [class get myclass] { 
        set search "$search@[lindex $pair 0]@[lindex $pair 1]@"
      }
      log local0. "String replace=$search"
      STREAM::expression $search
      STREAM::enable
    }
    

    Then create a string data class myclass as follows...

    Name                                      Value
    /secureapp/connect/report_en/REP   /en
    /peter                             /pan
    

    And get the following output from a logs

    Rule /Common/myrule : ...in HTTP_REQUEST
    Rule /Common/myrule : ...in HTTP_RESPONSE
    Rule /Common/myrule : search=@/secureapp/connect/report_en/REP@/en@@/peter@/pan@
    

    And the resulting web page...

    It works!
    
    /en
    /pan
    

22 Replies

  • Hi Kevin

     

    One more request , i would like to get the above iRule triggered only when end user browses www.myweb.com . The reason is that there are multiple websites hosted on backend physical servers (residing behind F5) ; however those websites are represented by F5 Virtual IP address.

     

    Regards , Ankur

     

  • when HTTP_REQUEST {
      log local0. "..in HTTP_REQUEST"
      set host [string tolower [HTTP::host]]
      if {$host ne "www.myweb.com"} { return }
       no replacement for requests
      STREAM::disable
       disable compression server side
      HTTP::header remove "Accept-Encoding"
    }
    when HTTP_RESPONSE {
      log local0. "...in HTTP_RESPONSE"
      if {$host ne "www.myweb.com"} { return }
       only replace text content
      if {!([HTTP::header value Content-Type] contains "text")}{ return}
    
      set search ""
      foreach pair [class get myclass] { 
        set search "$search@[lindex $pair 0]@[lindex $pair 1]@"
      }
      log local0. "String replace=$search"
      STREAM::expression $search
      STREAM::enable
    }
    
  • Hi Kevin

     

    The above is not working . I configured the above iRule and assigned it to VS along with enabling stream. I have built a dummy URL on the backened webserver and when i browse this URL , the URL in the address bar remains unchanged ]

     

    Regards,

     

    Ankur

     

  • Hi Kevin,

     

    The URL recommended by you contains the solutions which are difficult to understand and which doesnt mention the shortening of URIs . Is there any other way of doing it ?

     

    Regards,Ankur

     

  • The above is not working . I configured the above iRule and assigned it to VS along with enabling stream. I have built a dummy URL on the backened webserver and when i browse this URL , the URL in the address bar remains unchanged

     

    i understand Kevin's irule does replace string (e.g. uri) in response from server. it does not affect if you browse the uri directly.

     

    Source URL : http://www.myweb.com/secureapp/connect/report_en/REP/XYZ

     

    Masked URL : http://www.myweb.com/en/XYZ

     

    do you want when browsing http://www.myweb.com/secureapp/connect/report_en/REP/XYZ, url in address bar is changed to http://www.myweb.com/en/XYZ but uri to server is still /secureapp/connect/report_en/REP/XYZ?

     

    or does user have to browse http://www.myweb.com/en/XYZ (http://www.myweb.com/secureapp/connect/report_en/REP/XYZ is no not available at all) but bigip changes uri when sending to server to /secureapp/connect/report_en/REP/XYZ?

     

  • Hi nitass

     

    Yes , you understood it correctly . My requirement is first one you mentioned in above statement .

     

    "when browsing http://www.myweb.com/secureapp/connect/report_en/REP/XYZ, url in address bar is changed to http://www.myweb.com/en/XYZ but uri to server is still /secureapp/connect/report_en/REP/XYZ "

     

    Regards, Ankur

     

  • e.g.

     config
    
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 41
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
    ltm pool foo {
        members {
            200.200.200.101:80 {
                address 200.200.200.101
            }
        }
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      if { [HTTP::host] ne "www.myweb.com" } {
        return
      }
    
      switch -glob [HTTP::path] {
        "/secureapp/connect/report_en/REP/*" {
          HTTP::redirect "http://www.myweb.com[string map {/secureapp/connect/report_en/REP/ /en/} [HTTP::uri]]"
        }
        "/en/*" {
          HTTP::uri [string map {/en/ /secureapp/connect/report_en/REP/} [HTTP::uri]]
        }
        default {
           do nothing
        }
      }
    }
    }
    
     trace
    
    [root@ve11a:Active:In Sync] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.24.1(46786) <-> 172.28.24.10(80)
    1403433548.8492 (0.0022)  C>S
    ---------------------------------------------------------------
    HEAD /secureapp/connect/report_en/REP/XYZ HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: www.myweb.com
    Accept: */*
    
    ---------------------------------------------------------------
    
    1403433548.8494 (0.0002)  S>C
    ---------------------------------------------------------------
    HTTP/1.0 302 Found
    Location: http://www.myweb.com/en/XYZ
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    ---------------------------------------------------------------
    
    1403433548.8524 (0.0030)  C>S
    ---------------------------------------------------------------
    HEAD /en/XYZ HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: www.myweb.com
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.14(46786) <-> 200.200.200.101(80)
    1403433548.8687 (0.0160)  C>S
    ---------------------------------------------------------------
    HEAD /secureapp/connect/report_en/REP/XYZ HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: www.myweb.com
    Accept: */*
    
    ---------------------------------------------------------------
    
  • Hi

     

    Thanks for the above rule . As per mentioned Redirect rule ,i believe this will be applicable only when someone browse www.myweb.com .With this redirection i assume ; the user should see http://www.myweb.com/en/XYZ in browser.

     

    But this URI "/secureapp/connect/report_en/REP/" is configured and embedded inside the sublinks of the same website as well . Hence , if any of the sub-sites or links embedded inside www.myweb.com , contains "/secureapp/connect/report_en/REP/ ", then also "/secureapp/connect/report_en/REP/ " should get replaced with /en

     

    Regards , Ankur

     

  • But this URI "/secureapp/connect/report_en/REP/" is configured and embedded inside the sublinks of the same website as well . Hence , if any of the sub-sites or links embedded inside www.myweb.com , contains "/secureapp/connect/report_en/REP/ ", then also "/secureapp/connect/report_en/REP/ " should get replaced with /en

     

    that part can be done by Kevin's irule. :-)