I have the following script to redirect a server 404 responses to a nice 404_error.htm page:
if( http.getResponseCode() != 404 ) break;
http.setResponseCode("404 Not Found");
http.redirect( "/404_error.htm" );
The problem is that the script returns a 302 and then a 200 in http watch. I would like to see at 404 repose code returned before the redirect takes place.
Line two of the rule does not have the desired effect, it seems that I could either do a 404 or a 302. Is there a way of combining the two?
Solved! Go to Solution.
With any knowledge of the system itself:
If you redirect in the HTTP header, the response code is 302. You will get a 200 later because the file you get redirected to exists.
Another option is to use the TrafficScript http.sendResponse() function to control how the 404 content is sent to the client:
bq. http.sendResponse( "404 Not Found", "text/html", $body,");
You'll need to fill $body with the content of your 404 message; either put it inline in your trafficscript rule, or pull it out of the 'extra files' store using resource.get().