Forum Discussion

12 Replies

  • I try this but doesn't still work:

     

    if {[string tolower [HTTP::host]] starts_with "client.u.test.com" && [HTTP::uri] starts_with "/up" }

    { HTTP::header replace host "other.u.test.com"

      HTTP::uri "/up/.*"

      pool Pool_other.u.test.com_1443

    }

    • Sanjay_Palande's avatar
      Sanjay_Palande
      Icon for Nacreous rankNacreous

      Can you give more details on url rewrite/translation. e.g. if incoming url is https://client.u.test.com/up/test1/test2, what should be the rewrite url?

    • Sanjay_Palande's avatar
      Sanjay_Palande
      Icon for Nacreous rankNacreous

      There is still confusion around, how uri after /up should be translated. If you can provide more details on it then it would be clear. But I'm assuming those shouldn't be changed. Considering it won't change, you can use below iRule

      when HTTP_REQUEST {
          set uri [string tolower [HTTP::uri]]
          switch -glob [string tolower [HTTP::host]] {
              "client.u.test.com" {
                if {$uri starts_with "/up" } {
      		  HTTP::header replace "Host" "other.u.test.com"
      		  pool Pool_other.u.test.com_1443
      	      return
                }
      	    }
             default {
      	    return  
            }
          }
        }

      If you need any other rewrite rule with uri after /up let me know and we can modify the iRule above

  • P_K's avatar
    P_K
    Icon for Altostratus rankAltostratus

    Try this

    when HTTP_REQUEST {

     

     if { ([string tolower [HTTP::host]] contains "client.u.test.com") and [HTTP::uri] starts_with "/up" } {

        HTTP::header replace Host "other.u.test.com"

        pool Pool_other.u.test.com_1443

         

      }

    }

  • Thanks Sanjay.

    Actually I need to modify the host (it's ok in your iRule: client.u.test.com

    --> other.u.test.com) but also the path after the first "/" --> client.u.test.com/up is rewrited other.u.test.com/down

     

    • Sanjay_Palande's avatar
      Sanjay_Palande
      Icon for Nacreous rankNacreous

      okay. You can use below

      when HTTP_REQUEST {
          set uri [string tolower [HTTP::uri]]
          switch -glob [string tolower [HTTP::host]] {
              "client.u.test.com" {
                if {$uri starts_with "/up" } {
      		  HTTP::header replace "Host" "other.u.test.com"
      		  HTTP::uri /[join [lreplace [split [string trimleft [HTTP::uri] /] /] 0 0 "down"] /]
      		  pool Pool_other.u.test.com_1443
      	      return
                 }
      	  }
             default {
      	    return  
            }
          }
        }
      • ckteur's avatar
        ckteur
        Icon for Cirrus rankCirrus

        I haven't been able to test yet, I will do it tomorrow...

        I forgot to say that the rewrite must allow all the possibilities behind "/down"

        like "other.u.test.com/down/*"

         

        Thanks for help

         

         

    • Sanjay_Palande's avatar
      Sanjay_Palande
      Icon for Nacreous rankNacreous

      what error do you receive? Above iRule does the same where it will rewrite the HOST header and rewrite the url by replacing /up by /down and add all other uri after /down

       

      Please enable logging in iRule to see what's happening?