I have a application page that tries to do a window.location.replace() to an internal url with a port (for example "http://omgwtf.whythisishappening.com:7787/sites/crap).
Is there any way I can catch this attempt using an Irule and instead go to the external version of this url?
Hi Marlon
window.location.replace is a javascript executed on the client. The load balancer could not affect this, unless you replace the command with streaming profiles or complex irules (not recommended).
If I were you I’d see if there was a way of rewriting the application itself.
An workaround, albeit ugly could be to have a virtual server listening to port 7787 with one sole purpose. To redirect traffic back to 80. As I said, this is quite ugly and depending on your application you might be in for some lovely redirect loops. As a matter of fact, if you try it and it works. Don’t tell anyone I wrote it. 
Example irule:
when HTTP_REQUEST {
HTTP::respond 301 Location http://omgwtf.whythisishappening.com[HTTP::uri]
}
/Patrik