Forum Discussion

TheManu's avatar
TheManu
Icon for Nimbostratus rankNimbostratus
Nov 12, 2007

data gets lost when URL redirect

I want to implement a URL redirect for the following URL:

 

 

https://test.company.com/branch/workinggroup

 

 

Destination is:

 

 

https://test.company.com/programs/logic.php

 

 

The purpose of this page is that a user may post XML data, which is put into the body of the page. The PHP file contains the logic to read this data and automatically create an order in our system.

 

 

 

When I use the following URL redirection, the request is the redirected but the data gets lost:

 

 

when HTTP_REQUEST { if { [HTTP::host] eq "test.company.com/branch/workinggroup"}{ HTTP::header replace "host" "test.company.com/programs/logic.php"}}

 

 

Does anyone know how to change the iRule to keep the order process working?

 

 

Thanks for your help.

5 Replies

  • Hi,

    The Host header value doesn't include the URI, so that rule should never get triggered to replace the Host header. Also, to be exact, you want to rewrite the host and URI--not send a 302 redirect. The redirect would result in the client sending a new GET request to the redirect location.

    Can you try this?

    
    when HTTP_REQUEST {
       if { [HTTP::host] eq "test.company.com"}{
          log local0. "Rewriting client request for host: [HTTP::header value Host], for URI: [HTTP::uri]"
          HTTP::header replace "host" "test.company.com"
          HTTP::uri "/programs/logic.php"
       }
    }

    The log statement will be written to /var/log/ltm. You can watch the log using 'tail -f /var/log/ltm'.

    Aaron
  • Thank you for reply.

    If i use this:

    when HTTP_REQUEST {
       if { [HTTP::host] eq "test.company.com"}{
          log local0. "Rewriting client request for host: [HTTP::header value Host], for URI: [HTTP::uri]"
          HTTP::header replace "host" "test.company.com"
          HTTP::uri "/programs/logic.php"
       }
    }

    the redirection will allways target the logic.php.

    May I use it like this?

    when HTTP_REQUEST {
       if { [HTTP::host] eq "test.company.com/branch1/workinggroup"}{
          log local0. "Rewriting client request for host: [HTTP::header value Host], for URI: [HTTP::uri]"
          HTTP::header replace "host" "test.company.com"
          HTTP::uri "/programs/logic1.php"
       }
    }

    when HTTP_REQUEST {
       if { [HTTP::host] eq "test.company.com/branch2/workinggroup"}{
          log local0. "Rewriting client request for host: [HTTP::header value Host], for URI: [HTTP::uri]"
          HTTP::header replace "host" "test.company.com"
          HTTP::uri "/programs/logic2.php"
       }
    }
  • Do you actually expect Host header values other than test.company.com? Assuming not, you could try this to verify the URI matches for the rewrite:

    
    when HTTP_REQUEST {
        check if the path of the request starts with "/branch1/workinggroup"
       if {[HTTP::path] starts_with "/branch1/workinggroup"}{
          HTTP::header replace "Host" "test.company.com"
          HTTP::uri "/programs/logic1.php"
        check if the path of the request starts with "/branch2/workinggroup"
       } elseif }{[HTTP::path] starts_with "/branch2/workinggroup"}{
          HTTP::header replace "Host" "test.company.com"
          HTTP::uri "/programs/logic2.php"
       }
    }

    If you do want to validate the Host header equals "test.company.com" you could wrap the path checks in an 'if'.

    Aaron
  • Hi Aaron,

     

     

    I can't use the Code you have just posted because I get an error:

     

     

    01070151:3: Rule [iRule1] error:

     

    line 1: [wrong args] [when HTTP_REQUEST ]

     

    line 2: [undefined procedure:

     

     

     

     

  • Me again,

     

     

    i've found the error in my code...

     

     

    ...the problem was a line break which the system didn't like

     

     

     

    Thank you very much...System is working now!!!