I haven't written PHP for a long time. Recently, because ThinkPHP is specified for a project, I have relived the PHP craze. Because I have been writing JavaScript for a long time, so I forgot that the PHP array can even customize the key... joke.
ThinkPHP does not use the PATHINFO mode by default. For popular frameworks, PATHINFO has become popular. What's even more surprising is that ThinkPHP supports routing, it is a bit similar to the routing of the Python network framework. Many people have previously viewed the content in localhost \. php in the PATHINFO mode of nginx on the internet. However, a simpler method has been found recently:
The code is as follows: |
Copy code |
Location /{ If (! -E $ request_filename ){ Rewrite ^ (. *) $/index. php? S = $1 last; Break; } } |
Or more advanced
Add the following configuration in the nf file:
The code is as follows: |
Copy code |
If (! -E $ request_filename) { Rewrite ^/(. *) index. php (. *) $1/index. php? S = $2 last; Break; } |
The nginx url rewriting mechanism is used to implement this function, and the configuration URL_MODEL => 1 does not need to be added to config. php of ThinkPHP.
Supplement:
I searched the internet for a lot of methods that didn't work. After studying for a day, I found that the following configuration can perfectly support 'URL _ model' => 2.
The code is as follows: |
Copy code |
Location/project /{ Index. php; If (! -E $ request_filename ){ Rewrite ^/project/(. *) $/project/index. php/$1 last; Break; } } Location ~ . + \. Php ($ | /){ Set $ script $ uri; Set $ path_info "/"; If ($ uri ~ "^ (. + \. Php) (/. + )"){ Set $ script $1; Set $ path_info $2; } Fastcgi_pass 127.0.0.1: 9000; Fastcgi_index index. php? IF_REWRITE = 1; Include/APMServ/nginx/conf/fastcgi_params; Fastcgi_param PATH_INFO $ path_info; Fastcgi_param SCRIPT_FILENAME $ document_root/$ script; Fastcgi_param SCRIPT_NAME $ script; } |
In this example, all requests under the project are forwarded to the index. php to process, that is, the single portal file of ThinkPHP. Then, the request for the php file is sent to fastcgi for processing, and the support for PATH_INFO is added.
After Nginx is restarted, URLs such as http: // localhost/project/Index/insert, http: // localhost/project/index. php/Index/delete can be accessed correctly.