Forum Discussion

Francois's avatar
Francois
Icon for Nimbostratus rankNimbostratus
May 20, 2019

Replace part of URI

Hi,

I am looking for an Irule to replace a part of URI.

URL = something/abc/azerty

I want to rewrite on server side to :

URL = thing.abc/azerty

Which command can select the first part of URI between /...../ ??

Thanks !

3 Replies

  • Snl's avatar
    Snl
    Icon for Cirrostratus rankCirrostratus
    1. Try below
    2.  
    when HTTP_REQUEST {
        if { [HTTP::uri] starts_with "/something/abc/azerty" } {
            HTTP::uri [string map {"/something/abc/azerty" "/thing.abc/azerty"} [HTTP::uri]]
        }
    }
  • It works but i want to do this :

    the client put in URL "something/abc/azerty

    F5 modifies this to "thing.abc/azerty"

    There is something behind this URL that i don't know (/test/page.html)

     

    When the server behind F5 respond, it sends a 302 to "thing.abc/azerty/noreply.html"

    Then the client has a 302 but he don't know this internal URL.

     

    How can i do to modify the response ?

     

    I find

    when HTTP_RESPONSE

    we can change the "Location" but how to modify the Host-response and the URI-response ?

     

    Thanks !

  • when HTTP_REQUEST {
     
    	#log "URL : [HTTP::host]"
     
    	#log "URI : [HTTP::path]"
     
    	
     
    	set URIclient [getfield [HTTP::uri] "/" 2]
     
    	log "URIclient = $URIclient"
     
    	set URIpath [getfield [HTTP::uri] "/" 3]
     
    	#log "URIpath = $URIpath"
     
    	set URIpathdef [string map -nocase [list /$URIclient ""] [HTTP::uri]]
     
    	log "URIpathdef = $URIpathdef"
     
     
     
    		
     
    	if { [SSL::verify_result] == 0 }{
     
    	  #log "Certificat OK"
     
    		HTTP::header insert "SSL_CLIENT_CERT" [X509::whole [SSL::cert 0]]
     
    	  HTTP::header replace Host "thing.$URIclient"
     
    	  HTTP::uri $URIpathdef
     
    	  #log "Acces = [HTTP::host][HTTP::uri]"
     
      }
     
       
     
    }
     
     
     
    when HTTP_REQUEST_SEND {
     
     
     
    }
     
     
     
    when HTTP_RESPONSE {
     
    	log "STATUS : [HTTP::status]"
     
    	log "LOCATION : [HTTP::header value "Location"]"
     
    }