Forum Discussion

alvaro_martinez's avatar
alvaro_martinez
Icon for Nimbostratus rankNimbostratus
Sep 21, 2006

HTTP Redirect header localtion + uri

Hi,

 

 

I have the next reply from web server

 

 

HTTP/1.1 302 Moved Temporarily

 

Set-Cookie: BIGipServerACC-80=674006794.20480.0000; expires=Thu, 21-Sep-2006 11:05:27 GMT; path=/

 

Date: Thu, 21 Sep 2006 08:20:32 GMT

 

Location: http://1.2.3.4:8060/mf/MFAgent66x0.SIS?r=yes

 

Content-Type: text/html

 

Transfer-Encoding: chunked

 

 

I want to change only the IP address of Location header but I want to add the same uri to Location header.

 

 

I can to build this rule that I have found in forums but I don´t know if the syntax are correct

 

 

when HTTP_REQUEST {

 

set my_loc "http://xxx.xxx.xxx.xxx[HTTP::uri]"

 

TCP::respond "HTTP/1.1 302 Found\r\nLocation: $my_loc\r\nConnection: close\r\nContent-Length: 0\r\n\r\n"

 

TCP::close

 

}

 

 

Can you help me with any solutions or rule?

 

 

 

Regards

6 Replies

  • Hello,

     

     

    I think it's safer to look for a 302 response code and replace the Location header's host value if it's set to the value you want to replace, rather than generating the full response in the example you quoted.

     

     

    
    when HTTP_RESPONSE {
       if { [HTTP::status] contains "302" && [string tolower [HTTP::header Location]] contains "host_to_replace" }{
          log local0. "Original Location: [HTTP::header Location]"
          log local0. "New Location: [string map -nocase {"host_to_replace" "new_host"} [HTTP::header Location]]"
          HTTP::header replace Location [string map -nocase {"host_to_replace" "new_host"} [HTTP::header Location]]
          log local0. "Replaced Location with: [HTTP::header Location]"
       }
    }

     

     

    Note: I left log statements in the rule to verify the replacement is being done as expected. The output is written to the /var/log/ltm log file. After you're done testing the rule, either comment out or delete the log lines.

     

     

    I didn't test this completely, so repost here if you have any problems.

     

     

    Aaron
  • Hi

     

     

    Thanks you for your reply and sorry for my delay reply because I have had to upgrade the F5 version for test this rule.

     

     

    The rule work perfect but I also need to change port of Location header from 8060 to 80 in rewrite Location header reply.

     

     

     

    Thanks for advance

     

     

    Example

     

     

    Original request

     

     

    GET /mf HTTP/1.1

     

    TE: deflate,gzip;q=0.3

     

    Connection: TE, close

     

    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*

     

    Accept-Charset: iso-8859-1,*,utf-8

     

    Accept-Language: en-US

     

    Host: xxx.xxx.xxx.xxx:8060

     

     

    Reply Redirect reply

     

     

    HTTP/1.1 302 Moved Temporarily

     

    ate: Mon, 02 Oct 2006 13:58:52 GMT

     

    Location: http://IP_redirect:8060/mf/MFAgent66x0.SIS?r=yes

     

    Content-Type: text/html

     

    Transfer-Encoding: chunked

     

    Connection: Close

     

    Set-Cookie: BIGipServerACC-80=674006794.20480.0000; expires=Mon, 02-Oct-2006 17:03:57 GMT; path=/

     

     

     

  • Hi,

    If the original 302 redirect sent from the server contains a port, you can just add the original port to the rule in the string to replace. You don't need to specify the port in the string you are putting in, if it's 80, as it's the default port for http.

     
     when HTTP_RESPONSE { 
        if { [HTTP::is_redirect] && [string tolower [HTTP::header Location]] contains "host_to_replace:8060" }{ 
           HTTP::header replace Location [string map -nocase {"host_to_replace:8060" "new_host"} [HTTP::header Location]] 
        } 
     } 
     

    Aaron
  • Thanks ver much The las solutions do not change the location value and do not leave any logs. I look like I am not even starting and incident with the iRule.

     

    This is the only one that has work so far, but only works for one server

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::status] contains "302" && [string tolower [HTTP::header Location]] contains "server01" }{ HTTP::header replace Location [string map -nocase {"server01" "www.site.com"} [HTTP::header Location]]

     

    }

     

    }
  • Hi glazarte,

     

     

    Can you test the suggestion in this post (Click here) and reply there with any updates?

     

     

    Thanks,

     

    Aaron