Forum Discussion
Can I use a STREAM profile to replace response status code?
We have a smart 404 page that Google and other bots do not appreciate. It throws a 200 OK instead of a 404 Not Found. I can't do much on the server side to change this behavior, so I am looking to the BIG-IP for help. Can I replace the status code in the response using a STREAM profile?
I followed this post - realizing it's not exactly what I am looking to do. It does not replace the status code. Basic HTTP STREAM Profile
I've seen the payload approach where you gather some bytes and do a replace on that, but I think it requires recursion to gather all of the data and it seems messy. I was hoping the STREAM profile approach would work here. Any help would be appreciated!
Here is what my General_Not_Found_iRule currently looks like:
when HTTP_REQUEST {
collect the uri of the request
> convert uri to lower but keep original intact
set uri [HTTP::uri]
set lowerUri [string tolower [HTTP::uri]]
identify the uri that will trigger the 404 replacement in response
> instantiating variables is rarely a bad idea
set notFoundTriggerString "/404/pages/default.aspx"
set notFoundTriggered 0
disable the STREAM profile until we need it
STREAM::disable
if { $lowerUri contains $notFoundTriggerString } {
tell server not to compress the response
> the stream functions do not work with a compressed response
HTTP::header remove "Accept-Encoding"
set the not found flag to 1 for execution in the response
set notFoundTriggered 1
}
}
when HTTP_RESPONSE {
if { $notFoundTriggered equals 1 } {
set the find/replace expression for the STREAM profile
> it looks ugly, but it's the right syntax...
STREAM::expression "@200 OK@404 Not Found@"
now enable the STREAM profile
STREAM::enable
}
}
Hi JP,
UPDATE: Deleted my previous posting to avoid confusion, it has contained somewhat wrong information... 😉
The [STREAM] profile can't be used for this task. You have to collect the [HTTP::payload] of the original response and then create a new [HTTP::response 404] referencing the collected payload.
For further information: https://devcentral.f5.com/questions/changing-http-reponse-status-code
Cheers, Kai
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