Forum Discussion

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

Irule modify host, uri on response

Hello,

 

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.

 

when HTTP_REQUEST {

  if { ([HTTP::host] equals "test.domain.be") } {

    set uris [HTTP::uri]

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

    HTTP::uri $newuri

    HTTP::host "test.newdomain.be"

  }

}

 

So the user gives in a url. for example: test.domain.be/abc. We translate this into: test.newdomain.be/test/abc. 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
    Host: google.com
    Accept: */*

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

    #--- RESPONSE ---#
    HTTP/1.1 301 Moved Permanently
    Location: http://www.google.com/
    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 "https://www.google.uk"
      }
    }

    KR,

    Dario.