Forum Discussion

jasona_40790's avatar
jasona_40790
Icon for Nimbostratus rankNimbostratus
Jun 14, 2012

need to rewrite HTTP 200 status code to HTTP 503

Hello,

 

 

I am performing website maintenance and need to bring down our website for a few hours. I will be

 

serving a friendly maintenance page during this time. However, when Google comes by during the

 

maintenance period this will present a problem for indexing. I am running BigIP version 10.2.3

 

 

Google strongly recommends that we return a 503 HTTP result code during the maintenance window:

 

http://googlewebmastercentral.blogs...anned-site-

 

downtime.htmlhttp://googlewebmastercentral.blogspot.com/2011/01/how-to-deal-with-planned-site-

 

downtime.html

 

There are similiar posts to mine in these forums, but none resolve what I am trying to do. I want to

 

serve a maintenance page from a pool in VIP and have the F5 rewrite the result code from a 200 to a 503.

 

I am able to apply the iRule to the VIP, however, it does not serve my maintenance page. This is my

 

iRule:

 

 

when HTTP_REQUEST {

 

HTTP::respond 503 noserver Retry-After: 10800

 

}

 

 

Thanks,

 

 

 

  • Richard__Harlan's avatar
    Richard__Harlan
    Historic F5 Account
    What version are you running? The HTTP::header should be able to run the the HTTP_REQUEST_SEND event.
  • I am running version 10.2.3 Build 112.0. The iRule correct re-writes from HTTP 200 to 300 without this line:

     

     

    HTTP::header replace Retry-After: 10800

     

     

    However, as soon as I add that line to the iRule, the VIP will no longer serve traffic as mentioned above:

     

    when HTTP_REQUEST_SEND {

     

    HTTP::header replace Retry-After: 10800

     

    TCP::collect 12

     

     

    }

     

    when SERVER_DATA {

     

    if {[findstr [TCP::payload 12] "200"] == "200"} {

     

    TCP::payload replace 9 3 "503"

     

    }

     

    }

     

     

     

    So, it appears that the HTTP_REQUEST_SEND is working.

     

    Thanks for your help.
  • Richard__Harlan's avatar
    Richard__Harlan
    Historic F5 Account
    Ok I am a idiot there is two issues first HtTP_REQUEST_SEND should allow you to change headers but I think we have to be in server side context. The main problem is I told you to put the HTTP::header in HTTP_REQUEST_SEND. This is the event right before the LTM sends the request to the server side proxy. So this is the request to the server. When you need to change the response to the client. I fix the rule and ran it though some test and it seem to work and change the header. Again sorry for flipping the events

     

     

    when HTTP_REQUEST_SEND {

     

    TCP::collect 12

     

    log local0. "Added header"

     

     

    }

     

    when SERVER_DATA {

     

    if {[findstr [TCP::payload 12] "200"] == "200"} {

     

    TCP::payload replace 9 3 "503"

     

    }

     

    }

     

    when HTTP_RESPONSE {

     

    HTTP::header replace Retry-After 10800

     

    }
  • Richard,

     

     

    It works, thank you. There is one more thing I'm hoping to do here. The 503 status text response is 'HTTP/1.1 503 OK'. How do I get this to be 'HTTP/1.1 503 Service Unavailable'?

     

     

    Thanks.
  • Richard__Harlan's avatar
    Richard__Harlan
    Historic F5 Account
    If you want to change more data then you would have to do the following. Note it will over write more of the page from the pool member

     

     

    when HTTP_REQUEST_SEND {

     

    TCP::collect 32

     

    log local0. "Added header"

     

     

    }

     

    when SERVER_DATA {

     

    if {[findstr [TCP::payload 32] "200"] == "200"} {

     

    TCP::payload replace 9 23 "503 Service Unavailable"

     

    }

     

    }

     

    when HTTP_RESPONSE {

     

    HTTP::header replace Retry-After 10800

     

    }