服务器环境 linux/apache/mysql 问题描述 服务器开启了伪静态,并且也设置了伪静态文件.htaccess,但是伪静态不起作用,所有页面都跳转到了首页,我的伪静态文件如下:
- rewriteEngine on
- AcceptPathInfo On
- RewriteBase /
- rewritecond %{request_FILENAME} !-d
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_URI} !\.(css|js|png|jpeg|gif)$
- RewriteRule ^(.*)$ /index.php/$1 [QSA,PT,L]
复制代码解决思路 1、伪静态文件.htaccess是否起作用,于是我将我将首页修改为index.aaa
- RewriteRule ^(.*)$ /index.aaa/$1 [QSA,PT,L]
复制代码 此时发现网站是打不开的,所以断定伪静态文件起作用,并且能够定位到index.php. 2、此时分析可能是index.php 后的内容获取不到,获取此内容是通过path_info 进行获取,所以检测是否能够获取到path_info
- echo $_SERVER['PATH_INFO'];
复制代码 3、打印出来的结果为空白,继续打印$_Server;
- echo $_SERVER;
复制代码 打印出的结果为:
- array(64) {
- ["DOCUMENT_ROOT"]=>
- string(30) "/usr/home/qxu1780990217/htdocs"
- ["GATEWAY_INTERFACE"]=>
- string(7) "CGI/1.1"
- ["HTTP_ACCEPT"]=>
- string(63) "text/html,APPlication/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
- ["HTTP_ACCEPT_ENCODING"]=>
- string(13) "gzip, deflate"
- ["HTTP_ACCEPT_LANGUAGE"]=>
- 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"
- ["HTTP_cache_CONTROL"]=>
- string(8) "no-cache"
- ["HTTP_CONNECTION"]=>
- string(10) "keep-alive"
- ["HTTP_COOKIE"]=>
- string(42) "PHPSESSID=5d1dac4ecd19a129494040cd0bee0bfe"
- ["HTTP_HOST"]=>
- string(22) "qxu1780990217.my3w.com"
- ["HTTP_pragma"]=>
- string(8) "no-cache"
- ["HTTP_UPGRADE_INSECURE_REQUESTS"]=>
- string(1) "1"
- ["HTTP_USER_AGENT"]=>
- string(73) "Mozilla/5.0 (windows NT 10.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0"
- ["PATH"]=>
- string(13) "/bin:/usr/bin"
- ["PHPRC"]=>
- string(40) "/var/www/php54/hichina_ini/qxu1780990217"
- ["QUERY_STRING"]=>
- string(0) ""
- ["REDIRECT_DOCUMENT_ROOT"]=>
- string(30) "/usr/home/qxu1780990217/htdocs"
- ["REDIRECT_GATEWAY_INTERFACE"]=>
- string(7) "CGI/1.1"
- ["REDIRECT_HTTP_ACCEPT"]=>
- string(63) "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
- ["REDIRECT_HTTP_ACCEPT_ENCODING"]=>
- string(13) "gzip, deflate"
- ["REDIRECT_HTTP_ACCEPT_LANGUAGE"]=>
- 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"
- ["REDIRECT_HTTP_CACHE_CONTROL"]=>
- string(8) "no-cache"
- ["REDIRECT_HTTP_CONNECTION"]=>
- string(10) "keep-alive"
- ["REDIRECT_HTTP_COOKIE"]=>
- string(42) "PHPSESSID=5d1dac4ecd19a129494040cd0bee0bfe"
- ["REDIRECT_HTTP_HOST"]=>
- string(22) "qxu1780990217.my3w.com"
- ["REDIRECT_HTTP_PRAGMA"]=>
- string(8) "no-cache"
- ["REDIRECT_HTTP_UPGRADE_INSECURE_REQUESTS"]=>
- string(1) "1"
- ["REDIRECT_HTTP_USER_AGENT"]=>
- string(73) "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0"
- ["REDIRECT_PATH"]=>
- string(58) "/bin:/bin/sbin/:/usr/sbin/:/usr/bin/:/usr/local/bin/:/sbin"
- ["REDIRECT_QUERY_STRING"]=>
- string(0) ""
- ["REDIRECT_REMOTE_ADDR"]=>
- string(13) "36.24.243.135"
- ["REDIRECT_REMOTE_PORT"]=>
- string(5) "59458"
- ["REDIRECT_REQUEST_METHOD"]=>
- string(3) "GET"
- ["REDIRECT_REQUEST_URI"]=>
- string(11) "/brand.html"
- ["REDIRECT_SCRIPT_FILENAME"]=>
- string(41) "/usr/home/qxu1780990217/htdocs/brand.html"
- ["REDIRECT_SCRIPT_NAME"]=>
- string(11) "/brand.html"
- ["REDIRECT_SERVER_ADDR"]=>
- string(14) "139.129.150.40"
- ["REDIRECT_SERVER_ADMIN"]=>
- string(32) "[email protected]"
- ["REDIRECT_SERVER_NAME"]=>
- string(22) "qxu1780990217.my3w.com"
- ["REDIRECT_SERVER_PORT"]=>
- string(2) "80"
- ["REDIRECT_SERVER_PROTOCOL"]=>
- string(8) "HTTP/1.1"
- ["REDIRECT_SERVER_SIGNATURE"]=>
- string(0) ""
- ["REDIRECT_SERVER_SOFTWARE"]=>
- string(6) "Apache"
- ["REDIRECT_STATUS"]=>
- string(3) "200"
- ["REDIRECT_unique_ID"]=>
- string(24) "Wt8iggqjzDYAADQ3dj4AAAAK"
- ["REDIRECT_URL"]=>
- string(11) "/brand.html"
- ["REMOTE_ADDR"]=>
- string(13) "36.24.243.135"
- ["REMOTE_PORT"]=>
- string(5) "59458"
- ["REQUEST_METHOD"]=>
- string(3) "GET"
- ["REQUEST_URI"]=>
- string(11) "/brand.html"
- ["SCRIPT_FILENAME"]=>
- string(40) "/usr/home/qxu1780990217/htdocs/index.php"
- ["SCRIPT_NAME"]=>
- string(10) "/index.php"
- ["SERVER_ADDR"]=>
- string(14) "139.129.150.40"
- ["SERVER_ADMIN"]=>
- string(32) "[email protected]"
- ["SERVER_NAME"]=>
- string(22) "qxu1780990217.my3w.com"
- ["SERVER_PORT"]=>
- string(2) "80"
- ["SERVER_PROTOCOL"]=>
- string(8) "HTTP/1.1"
- ["SERVER_SIGNATURE"]=>
- string(0) ""
- ["SERVER_SOFTWARE"]=>
- string(6) "Apache"
- ["UNIQUE_ID"]=>
- string(24) "Wt8iggqjzDYAADQ3dj4AAAAK"
- ["ORIG_PATH_INFO"]=>
- string(11) "/brand.html"
- ["ORIG_PATH_TRANSLATED"]=>
- string(40) "/usr/home/qxu1780990217/htdocs/index.php"
- ["PHP_SELF"]=>
- string(10) "/index.php"
- ["REQUEST_TIME_FLOAT"]=>
- float(1524572802.4798)
- ["REQUEST_TIME"]=>
- int(1524572802)
- }
-
-
复制代码 发现并没有PATH_INFO,但是有一个ORIG_PATH_INFO 4、查找php手册,发现
- 'ORIG_PATH_INFO'
- Original version of 'PATH_INFO' before processed by PHP.
复制代码 即”ORIG_PATH_INFO“是“PATH_INFO”在被PHP处理之前的版本。 5、最终解决办法
- if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) ) $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
复制代码完美! |