Forum Discussion

JP_135500's avatar
JP_135500
Icon for Nimbostratus rankNimbostratus
Dec 15, 2015

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
    }       
}

1 Reply