From 17fb8ffd6439fcd140b486936900410a58787ac3 Mon Sep 17 00:00:00 2001 From: joyqi Date: Wed, 11 Dec 2013 17:41:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E6=AD=A3iis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- var/Typecho/Request.php | 86 ++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/var/Typecho/Request.php b/var/Typecho/Request.php index f77b4fcb..e11e8d48 100644 --- a/var/Typecho/Request.php +++ b/var/Typecho/Request.php @@ -39,6 +39,14 @@ class Typecho_Request */ private $_server = array(); + /** + * _requestUri + * + * @var string + * @access private + */ + private $_requestUri = NULL; + /** * 客户端ip地址 * @@ -306,7 +314,52 @@ class Typecho_Request public function getRequestUrl() { $scheme = $this->isSecure() ? 'https' : 'http'; - return $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + return $scheme . '://' . $_SERVER['HTTP_HOST'] . $this->getRequestUri(); + } + + /** + * 获取请求地址 + * + * @access public + * @return string + */ + public function getRequestUri() + { + if (!empty($this->_requestUri)) { + return $this->_requestUri; + } + + //处理requestUri + $requestUri = '/'; + + if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch + $requestUri = $_SERVER['HTTP_X_REWRITE_URL']; + } elseif ( + // IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem) + isset($_SERVER['IIS_WasUrlRewritten']) + && $_SERVER['IIS_WasUrlRewritten'] == '1' + && isset($_SERVER['UNENCODED_URL']) + && $_SERVER['UNENCODED_URL'] != '' + ) { + $requestUri = $_SERVER['UNENCODED_URL']; + } elseif (isset($_SERVER['REQUEST_URI'])) { + $requestUri = $_SERVER['REQUEST_URI']; + if (isset($_SERVER['HTTP_HOST']) && strstr($requestUri, $_SERVER['HTTP_HOST'])) { + $parts = @parse_url($requestUri); + + if (false !== $parts) { + $requestUri = (empty($parts['path']) ? '' : $parts['path']) + . ((empty($parts['query'])) ? '' : '?' . $parts['query']); + } + } + } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI + $requestUri = $_SERVER['ORIG_PATH_INFO']; + if (!empty($_SERVER['QUERY_STRING'])) { + $requestUri .= '?' . $_SERVER['QUERY_STRING']; + } + } + + return $this->_requestUri = $requestUri; } /** @@ -364,36 +417,7 @@ class Typecho_Request $pathInfo = NULL; //处理requestUri - $requestUri = NULL; - - if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch - $requestUri = $_SERVER['HTTP_X_REWRITE_URL']; - } elseif ( - // IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem) - isset($_SERVER['IIS_WasUrlRewritten']) - && $_SERVER['IIS_WasUrlRewritten'] == '1' - && isset($_SERVER['UNENCODED_URL']) - && $_SERVER['UNENCODED_URL'] != '' - ) { - $requestUri = $_SERVER['UNENCODED_URL']; - } elseif (isset($_SERVER['REQUEST_URI'])) { - $requestUri = $_SERVER['REQUEST_URI']; - if (isset($_SERVER['HTTP_HOST']) && strstr($requestUri, $_SERVER['HTTP_HOST'])) { - $parts = @parse_url($requestUri); - - if (false !== $parts) { - $requestUri = (empty($parts['path']) ? '' : $parts['path']) - . ((empty($parts['query'])) ? '' : '?' . $parts['query']); - } - } - } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI - $requestUri = $_SERVER['ORIG_PATH_INFO']; - if (!empty($_SERVER['QUERY_STRING'])) { - $requestUri .= '?' . $_SERVER['QUERY_STRING']; - } - } else { - return $this->_pathInfo = '/'; - } + $requestUri = $this->getRequestUri(); //处理baseUrl $filename = (isset($_SERVER['SCRIPT_FILENAME'])) ? basename($_SERVER['SCRIPT_FILENAME']) : '';