Forum Discussion
HTTP:host in HTTP_RESPONSE
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
- koenning_107182
Nimbostratus
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 - hoolio
Cirrostratus
I updated the HTTP::host wiki page to remove the response events. Thanks for pointing this error out.
Aaron - palli_69943
Nimbostratus
You should probably also update https://devcentral.f5.com/wiki/iRul...PONSE.ashx
I was trying to do the same thing and wondering why it wasn't working since the docs said it should.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com