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

anisotropic’s picture

Version: » 4.6.0

I 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;

killes@www.drop.org’s picture

Category: bug » feature

not a bug.

magico’s picture

Version: 4.6.0 » x.y.z
mstevenson-1’s picture

Version: x.y.z » 5.1

Could 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?

marcingy’s picture

Version: 5.1 » 8.x-dev

Bumping version

jhedstrom’s picture

Status: Active » Postponed (maintainer needs more info)

Is this at all relevant anymore?

jhedstrom’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Closing due to inactivity.