Nginx does not support ThinkPHP PATHINFO

Source: Internet
Author: User
Tags php file

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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.