当虚拟主机下获取不到$_SERVER['REQUEST_URI']时,的解决方案

由于虚拟主机不能随意更换服务器,所以当获取不到$_SERVER['REQUEST_URI']时可通过代码实现,在项目入口文件中定义

if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { 
    // 先检查一下,这样IIS会被捕获。
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; 
  } elseif (isset($_SERVER['REDIRECT_URL'])) { 
    // 检查是否使用mod_rewrite
    $_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_URL']; 
  } elseif (isset($_SERVER['REQUEST_URI'])) { 
    $_SERVER['REQUEST_URI'] = $_SERVER['REQUEST_URI']; 
  } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { 
    // IIS 5.0作为CGI,PHP
    $_SERVER['REQUEST_URI'] = $_SERVER['ORIG_PATH_INFO']; 
    if (!empty($_SERVER['QUERY_STRING'])) { 
      $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; 
    } 
  } 

 

转载于:https://www.cnblogs.com/mengor/p/8011133.html

你可能感兴趣的:(当虚拟主机下获取不到$_SERVER['REQUEST_URI']时,的解决方案)