I also configured many times, the front is quick to give up, recently in the Learning Resuful framework write API, code implementation did not appear what problem, but this path_info environment configuration I get depressed you must have seen a path like this: http://www.04007.cn/ Index.php/home/index/action/3408.html, yes, this is Phpinfo mode. It can be seen from the above that there are several characteristics.
1,url with the full name of the entry file, i.e. index.php,
2, there is still a path behind the entry file, like the/home/index/action/3408.html above.
3, many of the frameworks are followed by/module/controller/method parameters, etc., thinkphp is the case. Of course, this does not necessarily have to be the module controller method composition.
According to common sense, index.php follow the path, then index.php is the equivalent of a folder. But in fact there is no index.php this folder, so if the phpinfo mode is not turned on, then this path parsing will be reported to find the file. The server will not execute index.php this file until Phpinfo mode is turned on. The configuration method from the server can also be seen.
I use the integrated installation environment Phpstudy, this environment has been used for a long time
Check these three configurations first
One:
Locate php.ini under the PHP installation folder,
Will
; cgi.fix_pathinfo=1
Switch
Cgi.fix_pathinfo = On
Save, restart the server
Some say it will
; cgi.fix_pathinfo=1
the previous; Removed, the change is
Cgi.fix_pathinfo=1
Save, restart the server.
But I try to find that this does not solve the problem, so decided to adopt the second method;
Two:
Open the Conf folder under the Apache installation folder, locate the following code found in the httpd.conf file
<directory/>options followsymlinksallowoverride noneorder deny,allowdeny from AllAcceptPathInfo on // Join this line of code is OK </Directory>
Unfortunately, following the above approach, it failed. Wood approach, can only try the third method;
Three:
In the configuration file, add
<files *.php>acceptpathinfo on</files>
This allows Apache to support PathInfo for PHP files.
So, and full of hope to try, unfortunately, still no success.
I think, this pathinfo with the URL, that will be because the Apache server does not open the Mod_rewrite module relationship? So I found it in Apache config file (httpd.conf file under the Conf folder in Apache installation directory):
#LoadModule Rewrite_module modules/mod_rewrite.so
Remove the previous # and replace it with the following:
LoadModule Rewrite_module modules/mod_rewrite.so
Here is how the Nginx server turns on Phpinfo mode:
Location ~ [^/]\.php (/|$) { # comment try_files $uri =404; To enable PathInfo #try_files $uri =404; #把这行代码注释, let the server not taste Try to load the path file fastcgi_pass unix:/tmp/php-cgi.sock; Fastcgi_index index.php; Include fastcgi.conf; Include pathinfo.conf; #加载phpinfo. conf configuration}
Restart the Nginx server. For the Apache server, you need to load the rewrite module first, the configuration in http.conf allowoverride none to change none to all, restart Apache. Include in the. htaccess file
Rewriteengine Onrewritecond%{request_filename}!-drewritecond%{request_filename}!-fRewriteRule ^ (. *) $ index.php/$1 [Qsa,pt,l]
Note: When configuring a virtual domain name, my configuration
I gave a successful configuration of my php.ini and HTTPD.COMF, I was in another computer did not succeed in the reason maybe I added a point to the project address configuration, such as my following configuration
DocumentRoot "E:\phpstudy\WWW\restful" <directory/> Options +indexes +followsymlinks +execcgi allowoverride all Order allow,deny- acceptpathinfo on Require all granted</directory >
Point to the root address of the project order item.
Download address for my configuration:
http://download.csdn.net/download/qq_27229113/9981419
Recently learning to write APIs with a restful framework, find yourself routing this problem
I point the virtual domain name to www.restfulapi.com/
The virtual domain address points to restfulapi this folder
My API directory is written in restful/index.php, there are two methods, the users and articles two methods
If I enter http://www.restfulapi.com/restful/Route I will find also reported this error notice:undefined Index:path_info in E:\phpstudy\WWW\restfulapi\ restful\index.php on line 107
{"Error": "Request resource not allowed"}
But when you enter this route, Http://www.restfulapi.com/restful/users
There is data feedback {"error": "User name cannot be empty"}
To print the loaded configuration in code index.php
Var_dump ($_server);
The feedback result is
Array (redirect_status) {["]=> string (3)" "["] ["Http_host"]=> string "www.restfulapi.com" ["H Ttp_connection "]=> string (Ten)" Keep-alive "[" Http_cache_control "]=> string (9)" Max-age=0 "[" Http_user_ag ENT "]=> string (108)" mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/61.0.3163.79 safari/537.36 "[" Http_upgrade_insecure_requests "]=& Gt String (1) "1" ["Http_accept"]=> string "TEXT/HTML,APPLICATION/XHTML+XML,APPLICATION/XML;Q=0.9,IMAGE/WEBP", image/apng,*/*;q=0.8 "[" Http_accept_encoding "]=> string (in)" gzip, deflate "[" Http_accept_language "]=> s Tring (+) "zh-cn,zh;q=0.8" ["PATH"]=> string (272) "C:\WINDOWS\SYSTEM32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Program Files (x86) \microsoft SQL server\100\tools\binn\; C:\Program Files\Microsoft SQL Server\100\tools\binn\; C:\Program Files\Microsoft SQL Server\100\dts\binn\; C:\adb " ["SystemRoot"]=> string (Ten) "C:\Windows" ["COMSPEC"]=> string "C:\Windows\system32\cmd.exe" ["PA Thext "]=> string". COM;. EXE;. BAT;. CMD;. VBS;. VBE;. JS;. JSE;. WSF;. WSH;. MSC "[" windir "]=> String (Ten)" C:\Windows "[" Server_signature "]=> string (0)" "[" Server_software "]=> ; String "apache/2.4.23 (Win32) openssl/1.0.2j php/5.5.38" ["SERVER_NAME"]=> string "www.restfulapi.com" ["Server_addr"]=> string (9) "127.0.0.1" ["Server_port"]=> string (2) "A" ["REMOTE_ADDR"]=> string (9) "127.0.0.1" ["Document_root"]=> string (+) "E:/phpstudy/www/restfulapi" ["Request_scheme"]=> string ( 4) "http" ["Context_prefix"]=> string (0) "" ["Context_document_root"]=> string "e:/phpstudy/www/rest Fulapi "[" Server_admin "]=> string" admin@phpStudy.net "[" Script_filename "]=> string" E:/phpstudy /www/restfulapi/restful/index.php "[" Remote_port "]=> sTring (5) "59338" ["Redirect_url"]=> string (+) "/restful/users" ["Gateway_interface"]=> string (7) "Cgi/1 .1 "[" Server_protocol "]=> string (8)" http/1.1 "[" Request_method "]=> string (3)" GET "[" Query_string "]= > string (0) "" ["Request_uri"]=> string "/restful/users" ["Script_name"]=> string "/restfu L/index.php "[" Path_info "]=> string (6)"/users "[" path_translated "]=> string (+)" E:\phpstudy\WWW\restfu Lapi\users "[" Php_self "]=> string"/restful/index.php/users "[" Request_time_float "]=> FLOAT (15055330 05.973) ["Request_time"]=> int (1505533005)} {"Error": "User name cannot be empty"}
Discovery ["Path_info"]=>string (6) "/users" indicates that this PATH_INFO configuration only points to the restful/users and restful/articles directories I suspect is the reason for my routing configuration in opening my . htaccess folder Rewriteengine Onrewritecond%{request_filename}!-drewritecond%{request_filename} !- Frewriterule ^ (. *) $ index.php/$1 [qsa,pt,l] and I find that when I run this http://www.restfulapi.com/restful/users route, I go through two jumps to access the final API. It feels like there's a problem.
After testing, the following personal conclusions have been drawn
In the actual non-API registration of the route is www.restfulapi.com, can complete the user registration, and we use the Resuful framework for the API
When registering a user, the route is www.restfulapi.com/restful/users and the article API Www.restfulapi.com/restful/articles routes can be
is the individual understanding of the route is not thorough enough! In summary, the above routing configuration and php.ini and http.conf configuration is the focus, the completion of the PHP PathInfo mode can be implemented,