How to change/rewrite a 200 HTTP code to another code (302)
                    
                
                
                    
                        book
                        
Article ID: CTX230974
                        
                    
                    
                        calendar_today
                        
Updated On: 
                    
                 
                
                    
                
                    
                    
                        
                            
Description
                        
                        
                            On this case we needed to change a 200 response from backend to a 302 redirect. Just mold the request to fit the 302 normal body
First we replace the status code, then the Message. Afterwards we insert the header and remove the body. Note: some other headers will be still present.
 
HTTP/1.1 302 Found
Location: http://www.iana.org/domains/example/
                         
                     
                    
                    
                    
                    
                        
                            
                                
Resolution
                            
                            
                                Example transformation result:
root@sol# curl -v http://WEBSITE
* Rebuilt URL to: http://WEBSITE
*   Trying WEBSITE...
* TCP_NODELAY set
* Connected to WEBSITE (xx.xx.xx.xx) port 80 (#0)
> GET / HTTP/1.1
> Host: xx.xx.xx.xx
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Tue, 19 Dec 2017 16:39:09 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Accept-Ranges: bytes
< Vary: Accept-Encoding
< Content-Type: text/html
< Location: www.google.pt
< ETag: "2c97a0-b519662d993d"
< Transfer-Encoding: chunked
<
add rewrite action remove_body delete "http.RES.BODY(200000)"
add rewrite action insert_location_header insert_http_header Location "\"https://www.google.pt\""
add rewrite action change_status_to_302 replace http.RES.STATUS 302
add rewrite action change_message_to_302 replace http.RES.STATUS_MSG "\"Found\""
add rewrite policy replace1_status http.RES.IS_VALID change_status_to_302
add rewrite policy replace2_Message http.RES.IS_VALID change_message_to_302
add rewrite policy replace3_header http.RES.IS_VALID insert_location_header
add rewrite policy replace4_body http.RES.IS_VALID remove_body
bind lb vserver apache_test -policyName replace1_status -priority 100 -gotoPriorityExpression NEXT -type RESPONSE
bind lb vserver apache_test -policyName replace2_Message -priority 110 -gotoPriorityExpression NEXT -type RESPONSE
bind lb vserver apache_test -policyName replace3_header -priority 120 -gotoPriorityExpression NEXT -type RESPONSE
bind lb vserver apache_test -policyName replace4_body -priority 130 -gotoPriorityExpression END -type RESPONSE
                            
                         
                        
                    
                    
                    
                    
                
                    
                        
                            Was this article helpful?
                        
                        
                            
                                thumb_up
                                Yes
                            
                            
                                thumb_down
                                No