Summary
Rewrite the headers in HTTP responses. (e.g. Location header)
Specifics
In this scenario, The back-end application infrastructure leverages different hosts, ports and URL paths and application/operations team wants to mask these backend host, ports and URL paths from the users during these redirects to show customer friendly URIs.
In the example 1 below, the backend infrastructure uses different hostname "www.internalsite127" and also different port "9081" and different URL path structure "/path". (i.e the Location header in original http response is "www.internalsite127.com:9081/page")
To change this, we script and add a response policy to our virtual server to ensure that users will see only "www.site.com" , using default http port and uses "/catalogue" as more customer friendly URL path. The response policy "rp1" first uses rule rr1 to check if this is a redirect by checking for 302 status code. It then uses rr2 rule to strip off the existing host/URL path from Location header "www.internalsite127.com:9081/page" which is 28 characters long and replaces it with "www.site.com/catalogue"
In example 2, if you just want to strip off the backend port and leave host/URL path as is (e.g. remove all ":908x" ports that backend may issue redirect for, then can use rule rr3 to match on those ports and use response policy "rp2" to strip off those 5 characters
Finally, Note you can have request policies and response policies tied to the same virtual server.
Sample Code/Configuration
example 1
csw-rule "rr1" response-status-code 302 302
csw-rule "rr2" response-header "Location" pattern "www.internalsite127.com:9081/page"
!
csw-policy "rp1" type response-rewrite
match "rr1" response-header-rewrite
match "rr2" rewrite response-header-replace "www.site.com/catalogue" offset 0 length 28
!
server virtual vs1 110.168.84.50
port http response-rewrite-policy "rp1"
example 2
csw-rule "rr3" response-header "Location" pattern ":908"!
csw-policy "rp2" type response-rewrite
match "rr1" response-header-rewrite
match "rr3" rewrite response-header-replace "" offset 0 length 5
Further Reading
If you want to rewrite the payload of HTTP responses, check this wikiHow to rewrite the body of a HTTP response
