Let Nginx support ThinkPHP URL rewriting and PATHINFO method sharing
Source: Internet
Author: User
ThinkPHP supports providing friendly URLs through PATHINFO and URLrewrite. you only need to set tags in the configuration file: The Nginx web search method does not work for a day, we found that the following configuration can perfectly support 'URL _ model' => 2.
Copy codeThe code is as follows:
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;
}
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.
Note that there must be a space between the if and the parentheses in the Nginx configuration file. Otherwise, the unknown ctictive error will be reported.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.