Forum Discussion

Bimbo_180412's avatar
Bimbo_180412
Icon for Nimbostratus rankNimbostratus
Apr 19, 2017

Irule to rewrite URL

Please I need an irule to rewrite URL. http://10.2.2.13/sav/dtl/anything/anything.html -> http://10.2.2.120:8081/anything/anything.html ; http://10.2.2.85:8081/anything/anything.html

 

10.2.2.13 is the VIP address and 10.2.2.120/85 are the pool member addresses. The most important part of the irule is that I want the /sav/dtl to be removed and any text entered after this to be carried over to the server side as this is the path that exists on the server. It's a kind of reverse proxy, the url with /sav/dtl is what the world knows.

 

  • Sorry I just noticed that you do not want a redirect but a pool assignment The key is you want to remove /sav/dtl/ and /sav/jog to remove these characters use the string range command. pool1 is the first server and pool 2 is the second server. Make sure the pool are using the 8081 port

    when HTTP_REQUEST {

    set Vuri [ string tolower [HTTP::uri]]

    if { $Vuri starts_with "/sav/dtl/"} then {
        set HTTP::uri to start 8 Characters from the start og it self
        HTTP::uri [string range [HTTP::uri] 8 end]
        pool pool1
    }
    elseif {$Vuri starts_with "/sav/jog/" } then { 
        HTTP::uri [string range [HTTP::uri] 8 end]
        pool srvpool2
    }
    

    }

  • I want the /sav/dtl or sav/jog URLs to stay the same when entered into the browser so doesn't want this to be transparent to the user. Thank you.

     

  • Here this irule should work for you when HTTP_REQUEST {

    set Vuri [ string tolower [HTTP::uri]]

    if { $Vuri starts_with "/sav/dtl/"} then {
        set the new_vuri variable starting 8 Characters from the start
        set new_Vuri [string range [HTTP::uri] 8 end]
        HTTP::redirect "http://10.2.2.120:8081$new_Vuri"
    }
    elseif {$Vuri starts_with "/sav/jog/" } then { 
        set new_Vuri [string range [HTTP::uri] 8 end]
        HTTP::redirect"http://10.2.2.85:8081$new_Vuri"
    }
    

    }

  • Sorry I just noticed that you do not want a redirect but a pool assignment The key is you want to remove /sav/dtl/ and /sav/jog to remove these characters use the string range command. pool1 is the first server and pool 2 is the second server. Make sure the pool are using the 8081 port

    when HTTP_REQUEST {

    set Vuri [ string tolower [HTTP::uri]]

    if { $Vuri starts_with "/sav/dtl/"} then {
        set HTTP::uri to start 8 Characters from the start og it self
        HTTP::uri [string range [HTTP::uri] 8 end]
        pool pool1
    }
    elseif {$Vuri starts_with "/sav/jog/" } then { 
        HTTP::uri [string range [HTTP::uri] 8 end]
        pool srvpool2
    }
    

    }

    • Bimbo_180412's avatar
      Bimbo_180412
      Icon for Nimbostratus rankNimbostratus

      Thanks for this Hectorm, I will test this tomorrow and revert back. It's the 'string range' command that I might have been looking for.

       

    • Hectorm's avatar
      Hectorm
      Icon for Nimbostratus rankNimbostratus

      Yes also notice that the range command starts at 0 and not 1 so I think you may need to change the 8 for a 7 since you want the last bracket not to be removed.

       

  • Sorry I just noticed that you do not want a redirect but a pool assignment The key is you want to remove /sav/dtl/ and /sav/jog to remove these characters use the string range command. pool1 is the first server and pool 2 is the second server. Make sure the pool are using the 8081 port

    when HTTP_REQUEST {

    set Vuri [ string tolower [HTTP::uri]]

    if { $Vuri starts_with "/sav/dtl/"} then {
        set HTTP::uri to start 8 Characters from the start og it self
        HTTP::uri [string range [HTTP::uri] 8 end]
        pool pool1
    }
    elseif {$Vuri starts_with "/sav/jog/" } then { 
        HTTP::uri [string range [HTTP::uri] 8 end]
        pool srvpool2
    }
    

    }

    • Bimbo_180412's avatar
      Bimbo_180412
      Icon for Nimbostratus rankNimbostratus

      Thanks for this Hectorm, I will test this tomorrow and revert back. It's the 'string range' command that I might have been looking for.

       

    • Hectorm_262752's avatar
      Hectorm_262752
      Icon for Cirrus rankCirrus

      Yes also notice that the range command starts at 0 and not 1 so I think you may need to change the 8 for a 7 since you want the last bracket not to be removed.

       

    • Bimbo_180412's avatar
      Bimbo_180412
      Icon for Nimbostratus rankNimbostratus

      Thanks, I will check that in the morning while testing.