What Happened?
- How to return custom response code and content.
Environment
- F5 Distributed Cloud
- HTTP Load Balancer
Resolution/Answer
There are 2 situations in this scenario:
1. The response is from our server
You can use the Custom Error Response feature if the response is returned by our server. Please refer to this article What is the Custom Error Response feature? to learn more details.
2. The response is from the original server
If the response is from the original server, you can use the WAF feature to achieve this.
Let's say if you want to add the custom error page for 404 error for the LB, you can follow the below steps to do that:
- Setting the WAF to block mode.
- In Advanced Configuration, Change the Allowed Response Status Codes setting from Default to custom and remove the 404 code.
- In Advanced Configuration, Change the Blocking Response Page setting from Default to Custom, and set what the response code wants to return and the blocking response.
Test Result:
Additional Information
- If the error codes are from your original server you can custom response code in most of the servers you used, like IIS, Nignx, you can set this in the server configuration file. It is not the best way to use WAF to achieve this.