I run a drupal instance at work on our internal network as a FAQ tool, and had problems using the site while using ssh tunnels from the outside. I tracked this down to a problem with request_uri() where the following case was not accounted for:
in $_SERVER
HTTP_HOST is something like this:
hostname:8080
because this is the port the client is using and passing along,
but SERVER_PORT is '80' and REQUEST_URI is just something like /drupal/?q=support
the following is a quick hack to fix this, intended not as a patch, but just to illutstrate an edge-case and a way to work around it. There are no doubt better ways to do this. =)
the quick hack:
function request_uri() {
// echo "".print_r($_SERVER, 1)."
\n"; debugging? bah!
if(isset($_SERVER['HTTP_HOST'])) {
$host = explode(':', $_SERVER['HTTP_HOST']);
}
if($host[1] != $_SERVER['SERVER_PORT']) {
// boom, we're tunnelled, better supply an entire url
$uri = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
} else {
if (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
}
else {
if (isset($_SERVER['argv'])) {
$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0];
}
else {
$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
}
}
}
return check_url($uri);
}
Comments
Comment #1
anisotropic CreditAttribution: anisotropic commentedI forgot to mention this will only work if you also hack conf.php / settings.php:
// hack for tunneling
$arr = explode("/", $_SERVER['PHP_SELF']);
$arr = array_slice($arr, 0, -1);
$app_base = implode("/", $arr);
$base_url = "http://".$_SERVER['HTTP_HOST'] . $app_base;
Comment #2
killes@www.drop.org CreditAttribution: killes@www.drop.org commentednot a bug.
Comment #3
magico CreditAttribution: magico commentedComment #4
mstevenson-1 CreditAttribution: mstevenson-1 commentedCould someone please post how to get this to work for 5.1? I really need to get this working from inside an SSH tunnel. With this hack, does it matter what port you use as your local port for the tunnel?
Comment #5
marcingy CreditAttribution: marcingy commentedBumping version
Comment #6
jhedstromIs this at all relevant anymore?
Comment #7
jhedstromClosing due to inactivity.