Forum Discussion

Brian_Mayer_841's avatar
Brian_Mayer_841
Icon for Nimbostratus rankNimbostratus
Mar 04, 2008

Host header replace not working....

Hey all,

 

 

We're trying to replace the host portion of URLs for one of our virtual servers if they match a certain host string. I found the example below and applied it to the virtual server - but it's not working.

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "www.example.com"} {

 

HTTP::header replace "Host" "example.company.com"

 

}

 

}

 

 

If I go to the URL using www.example.com, the HTTP request is simply forwarded to the site and the host portion remains www.example.com - not example.company.com.

 

 

Any ideas where to start troubleshooting?

 

 

Thanks,

 

B

5 Replies

  • when HTTP_REQUEST {

     

    log local0. "http_request triggered host is: [HTTP::host]"

     

    if { [HTTP::host] equals "www.example.com"} {

     

    log local0. "host matched, replacing it by example.company.com"

     

    HTTP::header replace "Host" "example.company.com"

     

    }

     

    }

     

     

    Can you then show us the output of this test?

     

     

    the log will appear in /var/log/ltm

     

     

  • I see lots of these in the LTM log, but I still see the original www.example.com in the browser URL:

     

     

    Mar 4 16:32:09 tmm tmm[955]: Rule probes_redirect : http_request triggered host is: www.example.com

     

    Mar 4 16:32:09 tmm tmm[955]: Rule probes_redirect : host matched, replacing it with example.invitrogen.com

     

    Mar 4 16:32:10 tmm tmm[955]: Rule probes_redirect : http_request triggered host is: example.invitrogen.com
  • HTTP_request manipulate HTTP data that is being sent to the server

     

     

    this iRule will only change the HOST header between the bigip and the servers.

     

     

    On your browser you will always see the old URL since it will be based on the code provided by the web page.

     

     

    So if you want to see another URL in the browser it means you'll need to rewrite all the HTML content coming from the servers. you will need to use the HTTP_RESPONSE event to do so

     

     

     

    To do such a thing, you may have a look at the STREAM command Click here

     

     

    or look into the forum you'll see a lots of post about that.

     

  • Would a URL redirect work too? I'm sure it's less efficient since the clients would be redirected to the correct URL...
  • If your web server can provide http code based on the HTTP host yes.

     

     

    If whatever the host is, your web server will respond with code containing www.example.com then it won't be enough