It is possible to rewrite the environment variables with regular expressions as well. It is normal for ports in http_host to carry through to the web app. I think PHP (and other languages) do the same. If you omit :80, then it would also omit :80. I'm not sure why :80 is being used anywhere since that is the default. I also rewrote all my references to cgi.http_host to refer to a custom variable that has the port number removed.
I extract parts of the host name with reg-ex to work around this since the domain maps to the filesystem on my configuration. So i can convert something like this:
www.mydomain.com.test.com:8888 to be just
mydomain.com.
RewriteCond can have section with parenthesis and then you can refer to them in RewriteRule with % instead of $. I believe the syntax is close to this, but I have not tested this in apache right now.
RewriteCond %{HTTP_HOST} ((.*)(:(.*)|))
RewriteRule ^/(.*)$ ajp://%2:8009/$1 [L,P]
This one should be able to handle hosts with or without the port the same way. You can also use variables to store values in the web server config (setenv directive i think), and reuse them in multiple rewriterule statements.
If you are having trouble with rewrites in the future, may I suggest a debugging strategy where you temporarily rewrite all urls into a query string so that you can verify what values they have and then dump the URL scope until the values are what you want.
RewriteRule ^(.*)$ ajp://yourdomain:8009/index.cfm?theurl=$1&host=%{HTTP_HOST} [P,L]
You should probably consider if [P] by itself is correct for your application. I've usually always had rules where L is also defined (last) to avoid the web server processing other rules below it.
I'm currently using nginx to do this, so that's why I'm not sure about apache.