I am still interested in a rewrite based reply. For now I have noticed that Apache sets a REDIRECT_STATUS value if the url is altered by a rewrite rule. The original port number, if not 80 (note: I've not checked what happens under https), is part of the HTTP_HOST value. In PHP the following code "fixes" the SERVER_PORT value.
Code:
function fixServerPort($default=80) {
if (!empty($_SERVER['REDIRECT_STATUS'])) {
$start = strpos($_SERVER['HTTP_HOST'],':');
$port = ($start !== false) ? (int)substr($_SERVER['HTTP_HOST'],$start+1) : $default;
// correct 'SERVER_PORT' value
if ($port && $port != $default) {
$_SERVER['SERVER_PORT'] = $port;
}
}
}
It works under my circumstances. I can't say how generic it is.
Bookmarks