Forum Discussion

Dan_Brown_19294's avatar
Dan_Brown_19294
Icon for Nimbostratus rankNimbostratus
Mar 12, 2012

HTTP:host in HTTP_RESPONSE

Hi all,

 

 

Just attempting to update an HTTP_RESPONSE iRule to include a HTTP:host as well as it currently covers too much of the pool it is applied to.

 

 

 

According to https://devcentral.f5.com/wiki/iRul...PONSE.ashx I can use HTTP::host and according to https://devcentral.f5.com/wiki/iRules.HTTP__host.ashx I can use it against HTTP_RESPONSE.

 

 

 

When I try and implement it though I get an error stating:

 

[command is not valid in current event context (HTTP_RESPONSE)] [HTTP::host]

 

 

 

when HTTP_RESPONSE {

 

if { ( [HTTP::host] equals "example.com" ) and ( [HTTP::status] == 404 ) } {

 

HTTP::redirect "http://example.com/error.jpg"

 

}

 

}

 

 

 

The reason I am checking the host is multiple host headers are on the same virtual server and I only want to apply this redirect to 404s on the one host.

 

 

 

Is the wiki wrong or is it my implementation?

 

 

 

Many thanks,

 

Dan

 

 

3 Replies

  • Hi Dan,

    looking into the standard, Host seems to be a request header only, see

    http://www.ietf.org/rfc/rfc2616.txt , e.g. p127 14.23

    so this makes sense. Will double-check with a colleague, and then update the wiki

    However, use the following to achieve your goal:

    
    when HTTP_REQUEST {
        set my_host_header [HTTP::host]
    }
    when HTTP_RESPONSE {
        if { ( $my_host_header equals "example.com" ) and ( [HTTP::status] == 404 ) } {
            HTTP::redirect "http://example.com/error.jpg"
        }
    }

    Cheers,

    Christian
  • I updated the HTTP::host wiki page to remove the response events. Thanks for pointing this error out.

     

     

    Aaron