Redirecting a webpage

I currently have a ruby script that listens to a particular port on my
computer and prints out information about any traffic going through it.
The script uses HTTPProxyServer. However, there are times when I would
like to redirect traffic based on certain parts of the information that
I can access. Is there a way that I can do this using HTTPProxyServer,
or do I need to use something else? I haven’t been able to turn up
anything using a google search.