Recently used the LNMP one-click Install package 1.2 version, and then build the thinkphp program can not use PathInfo mode anyway. Find a lot of solutions online, and finally found the problem.
1, LNMP a key installation package php.ini inside cgi.fix_pathinfo=0. This value is 1 by default when PHP is installed properly. If you use LNMP one-click installation package must be modified to 1, of course, you can also modify the thinkphp source code.
2, modify your configuration file, comment out try_files $uri = 404; open include pathinfo.conf; then url_model=1 can support PathInfo.
Location ~ [^/]\.php (/|$) { # comment Try_files $uri =404, to enable PathInfo #try_files $uri =404; Fastcgi_pass Unix:/tmp/php-cgi.sock; Fastcgi_index index.php; Include fastcgi.conf; Include pathinfo.conf; }
3. If you think cgi.fix_pathinfo=1 is unsafe, you can use rewrite mode.
Under the virtual host root line, add the following
if (!-e $request _filename) { rewrite ^ (. *) $ /index.php?s=$1 last ; break; }
4. The reason why PathInfo is not available is that cgi.fix_pathinfo=0 $_server[' php_self ' is not getting index.php.
And the source of thinkphp
if (is_cgi) { //cgi/fastcgi mode $_temp = explode ('. php ', $_server[' php_self ']); Define (' _php_file_ ', RTrim (str_replace ($_server[' http_host '), ' ', $_temp[0]. php '), '/'); } else { define (' _php_file_ ', rtrim ($_server[' script_name '], '/')); }
Because $_server[' php_self ' gets less than index.php, $_temp is empty, resulting in _php_file_ for the. Php,u function The address that is generated is also. PHP is not accessible. If you do not want to modify the configuration of PHP can only modify the source code here. Change the If inside to be the same as the other one.