必威体育Betway必威体育官网
当前位置:首页 > IT技术

pathinfo 伪静态 详细解析PATH_INFO 和 ORIG_PATH_INFO技术分享

时间:2019-10-01 08:43:24来源:IT技术作者:seo实验室小编阅读:87次「手机版」
 

pathinfo

http://www.ape-men.com/bbs/43_1_1.html

服务器环境

linux/apache/mysql

问题描述

        服务器开启了伪静态,并且也设置了伪静态文件.htaccess,但是伪静态不起作用,所有页面都跳转到了首页,我的伪静态文件如下:

  1. rewriteEngine on
  2. AcceptPathInfo On
  3. RewriteBase /
  4. rewritecond %{request_FILENAME} !-d
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteCond %{REQUEST_URI} !\.(css|js|png|jpeg|gif)$
  7. RewriteRule ^(.*)$ /index.php/$1 [QSA,PT,L]
复制代码解决思路

        1、伪静态文件.htaccess是否起作用,于是我将我将首页修改为index.aaa

  1. RewriteRule ^(.*)$ /index.aaa/$1 [QSA,PT,L]
复制代码       此时发现网站是打不开的,所以断定伪静态文件起作用,并且能够定位到index.php.

        2、此时分析可能是index.php 后的内容获取不到,获取此内容是通过path_info 进行获取,所以检测是否能够获取到path_info

  1. echo $_SERVER['PATH_INFO'];
复制代码       3、打印出来的结果为空白,继续打印$_Server;
  1. echo $_SERVER;
复制代码       打印出的结果为:
  1. array(64) {
  2.   ["DOCUMENT_ROOT"]=>
  3.   string(30) "/usr/home/qxu1780990217/htdocs"
  4.   ["GATEWAY_INTERFACE"]=>
  5.   string(7) "CGI/1.1"
  6.   ["HTTP_ACCEPT"]=>
  7.   string(63) "text/html,APPlication/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
  8.   ["HTTP_ACCEPT_ENCODING"]=>
  9.   string(13) "gzip, deflate"
  10.   ["HTTP_ACCEPT_LANGUAGE"]=>
  11.   string(59) "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"
  12.   ["HTTP_cache_CONTROL"]=>
  13.   string(8) "no-cache"
  14.   ["HTTP_CONNECTION"]=>
  15.   string(10) "keep-alive"
  16.   ["HTTP_COOKIE"]=>
  17.   string(42) "PHPSESSID=5d1dac4ecd19a129494040cd0bee0bfe"
  18.   ["HTTP_HOST"]=>
  19.   string(22) "qxu1780990217.my3w.com"
  20.   ["HTTP_pragma"]=>
  21.   string(8) "no-cache"
  22.   ["HTTP_UPGRADE_INSECURE_REQUESTS"]=>
  23.   string(1) "1"
  24.   ["HTTP_USER_AGENT"]=>
  25.   string(73) "Mozilla/5.0 (windows NT 10.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0"
  26.   ["PATH"]=>
  27.   string(13) "/bin:/usr/bin"
  28.   ["PHPRC"]=>
  29.   string(40) "/var/www/php54/hichina_ini/qxu1780990217"
  30.   ["QUERY_STRING"]=>
  31.   string(0) ""
  32.   ["REDIRECT_DOCUMENT_ROOT"]=>
  33.   string(30) "/usr/home/qxu1780990217/htdocs"
  34.   ["REDIRECT_GATEWAY_INTERFACE"]=>
  35.   string(7) "CGI/1.1"
  36.   ["REDIRECT_HTTP_ACCEPT"]=>
  37.   string(63) "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
  38.   ["REDIRECT_HTTP_ACCEPT_ENCODING"]=>
  39.   string(13) "gzip, deflate"
  40.   ["REDIRECT_HTTP_ACCEPT_LANGUAGE"]=>
  41.   string(59) "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"
  42.   ["REDIRECT_HTTP_CACHE_CONTROL"]=>
  43.   string(8) "no-cache"
  44.   ["REDIRECT_HTTP_CONNECTION"]=>
  45.   string(10) "keep-alive"
  46.   ["REDIRECT_HTTP_COOKIE"]=>
  47.   string(42) "PHPSESSID=5d1dac4ecd19a129494040cd0bee0bfe"
  48.   ["REDIRECT_HTTP_HOST"]=>
  49.   string(22) "qxu1780990217.my3w.com"
  50.   ["REDIRECT_HTTP_PRAGMA"]=>
  51.   string(8) "no-cache"
  52.   ["REDIRECT_HTTP_UPGRADE_INSECURE_REQUESTS"]=>
  53.   string(1) "1"
  54.   ["REDIRECT_HTTP_USER_AGENT"]=>
  55.   string(73) "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0"
  56.   ["REDIRECT_PATH"]=>
  57.   string(58) "/bin:/bin/sbin/:/usr/sbin/:/usr/bin/:/usr/local/bin/:/sbin"
  58.   ["REDIRECT_QUERY_STRING"]=>
  59.   string(0) ""
  60.   ["REDIRECT_REMOTE_ADDR"]=>
  61.   string(13) "36.24.243.135"
  62.   ["REDIRECT_REMOTE_PORT"]=>
  63.   string(5) "59458"
  64.   ["REDIRECT_REQUEST_METHOD"]=>
  65.   string(3) "GET"
  66.   ["REDIRECT_REQUEST_URI"]=>
  67.   string(11) "/brand.html"
  68.   ["REDIRECT_SCRIPT_FILENAME"]=>
  69.   string(41) "/usr/home/qxu1780990217/htdocs/brand.html"
  70.   ["REDIRECT_SCRIPT_NAME"]=>
  71.   string(11) "/brand.html"
  72.   ["REDIRECT_SERVER_ADDR"]=>
  73.   string(14) "139.129.150.40"
  74.   ["REDIRECT_SERVER_ADMIN"]=>
  75.   string(32) "[email protected]"
  76.   ["REDIRECT_SERVER_NAME"]=>
  77.   string(22) "qxu1780990217.my3w.com"
  78.   ["REDIRECT_SERVER_PORT"]=>
  79.   string(2) "80"
  80.   ["REDIRECT_SERVER_PROTOCOL"]=>
  81.   string(8) "HTTP/1.1"
  82.   ["REDIRECT_SERVER_SIGNATURE"]=>
  83.   string(0) ""
  84.   ["REDIRECT_SERVER_SOFTWARE"]=>
  85.   string(6) "Apache"
  86.   ["REDIRECT_STATUS"]=>
  87.   string(3) "200"
  88.   ["REDIRECT_unique_ID"]=>
  89.   string(24) "Wt8iggqjzDYAADQ3dj4AAAAK"
  90.   ["REDIRECT_URL"]=>
  91.   string(11) "/brand.html"
  92.   ["REMOTE_ADDR"]=>
  93.   string(13) "36.24.243.135"
  94.   ["REMOTE_PORT"]=>
  95.   string(5) "59458"
  96.   ["REQUEST_METHOD"]=>
  97.   string(3) "GET"
  98.   ["REQUEST_URI"]=>
  99.   string(11) "/brand.html"
  100.   ["SCRIPT_FILENAME"]=>
  101.   string(40) "/usr/home/qxu1780990217/htdocs/index.php"
  102.   ["SCRIPT_NAME"]=>
  103.   string(10) "/index.php"
  104.   ["SERVER_ADDR"]=>
  105.   string(14) "139.129.150.40"
  106.   ["SERVER_ADMIN"]=>
  107.   string(32) "[email protected]"
  108.   ["SERVER_NAME"]=>
  109.   string(22) "qxu1780990217.my3w.com"
  110.   ["SERVER_PORT"]=>
  111.   string(2) "80"
  112.   ["SERVER_PROTOCOL"]=>
  113.   string(8) "HTTP/1.1"
  114.   ["SERVER_SIGNATURE"]=>
  115.   string(0) ""
  116.   ["SERVER_SOFTWARE"]=>
  117.   string(6) "Apache"
  118.   ["UNIQUE_ID"]=>
  119.   string(24) "Wt8iggqjzDYAADQ3dj4AAAAK"
  120.   ["ORIG_PATH_INFO"]=>
  121.   string(11) "/brand.html"
  122.   ["ORIG_PATH_TRANSLATED"]=>
  123.   string(40) "/usr/home/qxu1780990217/htdocs/index.php"
  124.   ["PHP_SELF"]=>
  125.   string(10) "/index.php"
  126.   ["REQUEST_TIME_FLOAT"]=>
  127.   float(1524572802.4798)
  128.   ["REQUEST_TIME"]=>
  129.   int(1524572802)
  130. }
  131.  
  132.   
复制代码       发现并没有PATH_INFO,但是有一个ORIG_PATH_INFO

        4、查找php手册,发现

  1. 'ORIG_PATH_INFO'
  2.     Original version of 'PATH_INFO' before processed by PHP.
复制代码       即”ORIG_PATH_INFO“是“PATH_INFO”在被PHP处理之前的版本。

        5、最终解决办法

  1. if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) ) $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
复制代码完美!

相关阅读

分享到:

栏目导航

推荐阅读

热门阅读