Forum Discussion

Jeroen_V_95572's avatar
Jeroen_V_95572
Icon for Nimbostratus rankNimbostratus
Aug 17, 2011

Outgoing header modification

Hello All,

 

 

I have a little problem on a BIG IP ASM v10 system.

 

 

I have created the following irule:

 

when HTTP_REQUEST {

 

set uri [HTTP::uri]

 

}

 

 

when HTTP_RESPONSE {

 

if { [HTTP::header "Location"] starts_with "http://www.backendserver.com"} {

 

set host "https://www.example.be"

 

HTTP::header replace "Location" $host$uri}

 

}

 

 

The Irule compiles and works but when I browse to e.g http://www.example.be/parameter1 it hits this Irule.

 

But The if statement was never matched because when you enter parameter1 then the www.example.be server responds and not the back end server.

 

 

Does anybody know an easier way to replace a part of the location header ?

 

 

Thanks in advance !

 

 

Regards

 

 

J

 

 

  • Hi Jeroen,

    I'm a bit confused. Does the response you want to rewrite contain a Location header with a value that starts with http://www.backendserver.com? Can you try logging the response headers in the iRule:

    when HTTP_REQUEST {
       set uri [HTTP::uri]
    }
    
    when HTTP_RESPONSE {
       log local0. "[IP::client_addr]:[TCP::client_port]: URI: $uri, status: [HTTP::status], Location: [HTTP::header "Location"]"
       if { [HTTP::is_redirect] and [HTTP::header "Location"] starts_with "http://www.backendserver.com"}  {
          set host "https://www.example.be"
          HTTP::header replace "Location" $host$uri
          log local0. "[IP::client_addr]:[TCP::client_port]: Rewriting Location to $host$uri"
       }
    }
    

    Aaron
  • Hi Aaron,

     

     

    I see my rule is executed but i did a configuration with the wrong variabeles.

     

    At this moment I get a response from the server with location: http://www.backendserver.com/someparamaters.

     

    This should be translated to https://www.example.com/someparameters.

     

     

    So the uri that is requested by the user is not the correct parameter, the correct parameter is the response that I get back from the backend server. So it's just a translation and not really a rederiction. I should translate backendserver into example.

     

     

    Can this be done by a simple Irule ?

     

     

    Thanks in advance !

     

     

    Regards,

     

     

    J

     

  • Hi Aaron,

     

     

    Again thanks for the great support, I searched the forum and found a reply on an existing topic.

     

    The configuration is now correct because of the map string command.

     

    With this option the backendserver is replaced with a domain name !

     

     

    Thanks for your effort !

     

     

    Gr,

     

     

    J

     

  • Sorry, I just realized the protocol wasn't prepended to the Location header. So the browser interprets it as a local URI which it appends to the requested protocol, host and URI. If you use this it should work:

    when HTTP_REQUEST {
       set uri [HTTP::uri]
       set host [HTTP::host]
    }
    
    when HTTP_RESPONSE {
       log local0. "[IP::client_addr]:[TCP::client_port]: URI: $uri, status: [HTTP::status], Location: [HTTP::header "Location"]"
       if { [HTTP::is_redirect] and [HTTP::header "Location"] starts_with "http://www.backendserver.com"}  {
          HTTP::header replace "Location" "https://$host$uri"
          log local0. "[IP::client_addr]:[TCP::client_port]: Rewriting Location to https://$host$uri"
       }
    }
    

    Aaron