Your iRule looks like it is only covering one of the two possible host names - test.example.com. There is no condition for removing the "/prod" string if the host name is prod.example.com which may be the cause of your 404 response. You can add a couple of log commands to the iRule to see what the before and after URIs look like. For example:
when HTTP_REQUEST {
log local0. "URI on client side is: [HTTP::uri]"
if { [HTTP::host] equals "prod.example.com" || [HTTP::host] equals "test.example.com" } {
HTTP::uri [string map { "/test" "" } [HTTP::uri] ]
log local0. "URI on server side changed to: [HTTP::uri]"
}
}
Also, if there is any chance the URI might contain only "/test" or "/prod" (e.g. "test.example.com/test" or "prod.example.com/prod") you should check for that possibility before executing the string map command as shown. Otherwise, it will leave you with a null URI which generates an error message to /var/log/ltm and stops the iRule from completing.