diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index b2f11cc33..e5b78571a 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -189,18 +189,18 @@ class CakeRequest implements ArrayAccess { * @return string URI The CakePHP request path that is being accessed. */ protected function _url() { - $pathInfo = env('PATH_INFO'); - if (!empty($pathInfo)) { - return $pathInfo; - } - foreach (array('PHP_SELF', 'REQUEST_URI', 'HTTP_X_REWRITE_URL', 'argv') as $var) { - if ($uri = env($var)) { - if ($var == 'argv') { - $uri = $url[0]; - } - break; - } + if (!empty($_SERVER['PATH_INFO'])) { + return $_SERVER['PATH_INFO']; + } elseif (isset($_SERVER['REQUEST_URI'])) { + $uri = $_SERVER['REQUEST_URI']; + } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) { + $uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']); + } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) { + $uri = $_SERVER['HTTP_X_REWRITE_URL']; + } elseif ($var = env('argv')) { + $uri = $var[0]; } + $base = $this->base; if (strpos($uri, $base) === 0) { diff --git a/lib/Cake/tests/cases/libs/cake_request.test.php b/lib/Cake/tests/cases/libs/cake_request.test.php index f0bf5216e..b2c96bbdb 100644 --- a/lib/Cake/tests/cases/libs/cake_request.test.php +++ b/lib/Cake/tests/cases/libs/cake_request.test.php @@ -1173,7 +1173,7 @@ class CakeRequestTestCase extends CakeTestCase { ), ), array( - 'Apache - No rewrite, document root set above top level cake dir, requesting root', + 'Apache - No rewrite, document root set above top level cake dir, reques root, no PATH_INFO', array( 'App' => array( 'base' => false, @@ -1185,9 +1185,8 @@ class CakeRequestTestCase extends CakeTestCase { 'SERVER_NAME' => 'localhost', 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php', - 'REQUEST_URI' => '/site/index.php/', + 'REQUEST_URI' => '/site/index.php/', 'SCRIPT_NAME' => '/site/index.php', - 'PATH_INFO' => '', 'PHP_SELF' => '/site/index.php/', ), ), @@ -1224,7 +1223,56 @@ class CakeRequestTestCase extends CakeTestCase { 'base' => '/site/index.php', 'webroot' => '/site/app/webroot/', ), - ) + ), + array( + 'Apache - w/rewrite, document root set above top level cake dir, request root, no PATH_INFO', + array( + 'App' => array( + 'base' => false, + 'baseUrl' => false, + 'dir' => 'app', + 'webroot' => 'webroot' + ), + 'SERVER' => array( + 'SERVER_NAME' => 'localhost', + 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', + 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php', + 'REQUEST_URI' => '/site/', + 'SCRIPT_NAME' => '/site/app/webroot/index.php', + 'PHP_SELF' => '/site/app/webroot/index.php', + ), + ), + array( + 'url' => '', + 'base' => '/site', + 'webroot' => '/site/', + ), + ), + array( + 'Apache - w/rewrite, document root above top level cake dir, request root, no PATH_INFO/REQUEST_URI', + array( + 'App' => array( + 'base' => false, + 'baseUrl' => false, + 'dir' => 'app', + 'webroot' => 'webroot' + ), + 'SERVER' => array( + 'SERVER_NAME' => 'localhost', + 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', + 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php', + 'SCRIPT_NAME' => '/site/app/webroot/index.php', + 'PHP_SELF' => '/site/app/webroot/index.php', + 'PATH_INFO' => null, + 'REQUEST_URI' => null, + ), + ), + array( + 'url' => '', + 'base' => '/site', + 'webroot' => '/site/', + ), + ), ); } @@ -1240,7 +1288,7 @@ class CakeRequestTestCase extends CakeTestCase { $request = new CakeRequest(); $this->assertEquals($expected['url'], $request->url, "url error"); $this->assertEquals($expected['base'], $request->base, "base error"); - $this->assertEquals($expected['webroot'],$request->webroot, "webroot error"); + $this->assertEquals($expected['webroot'], $request->webroot, "webroot error"); if (isset($expected['urlParams'])) { $this->assertEqual($_GET, $expected['urlParams'], "GET param mismatch"); }