Anything is possible with mod_rewrite. Here's an example from my config on how to redirect to HTTPS:
Code:
RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
You can find everything you need, e.g. how to check port numbers, in the documentation:
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
- Arch