Forum Discussion

Thomasvr's avatar
Icon for Nimbostratus rankNimbostratus
Jun 24, 2019

Irule modify host, uri on response



The scenario is that we have url that needs to be translated to another url. So this needs to be done at the request. And for the response the url needs to be translated back to its original url.

For the request this works and this is how we have done this.



  if { ([HTTP::host] equals "") } {

    set uris [HTTP::uri]

    set newuri "/test[string range [string tolower [HTTP::uri]] 0 end]"

    HTTP::uri $newuri

    HTTP::host ""




So the user gives in a url. for example: We translate this into: So there is uri and host translation.

How can we do this for the response? So everything what we did here but then in reverse?

1 Reply

  • Hello Thomasvr

    Actually this doesn't make sense.

    "Host" is a header which only applies to requests.

    #--- REQUEST ---#
    GET / HTTP/1.1
    User-Agent: curl/7.26.0
    Accept: */*

    The most similar header in the response is "Location" which indicates the URL for redirection.

    #--- RESPONSE ---#
    HTTP/1.1 301 Moved Permanently
    Content-Type: text/html; charset=UTF-8
    Date: Thu, 27 Jun 2019 00:40:48 GMT
    Expires: Sat, 27 Jul 2019 00:40:48 GMT
    Cache-Control: public, max-age=2592000
    Server: gws
    Content-Length: 219
    X-XSS-Protection: 0
    X-Frame-Options: SAMEORIGIN

    You can replace it using next iRule

    when HTTP_RESPONSE {
      if { [HTTP::is_redirect] }{
        HTTP::header replace Location ""