Enable nginx to support thinkphp URL rewriting and pathinfo

Source: Internet
Author: User
Tags php source code

Introduction: This is a detailed page for nginx to support thinkphp URL rewriting and pathinfo. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 343152 'rolling = 'no'>

Thinkphp supports providing friendly URLs through pathinfo and URL rewrite. You only need to set 'url _ model' => 2 in the configuration file. In Apache, you only need to enable the mod_rewrite module for normal access, but pathinfo is not supported by nginx by default, so we need to modify the nginx. conf file.

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.

1 Location/project /{
2 Index index. php;
3 if (! -E $ request_filename ){
4 rewrite ^/project/(. *) $/project/index. php/$1 last;
5 break;
6}
7}
8
9 location ~ . + \. Php ($ | /){
10 set $ script $ URI;
11 set $ path_info "/";
12 if ($ URI ~ "^ (. + \. Php) (/. + )"){
13 set $ script $1;
14 set $ path_info $2;
15}
16
17 fastcgi_pass 127.0.0.1: 9000;
18 fastcgi_index. php? If_rewrite = 1;
19 include/apmserv/nginx/CONF/fastcgi_params;
20 fastcgi_param path_info $ path_info;
21 fastcgi_param script_filename $ document_root/$ script;
22 fastcgi_param script_name $ script;
23}

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.

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/343152.html pageno: 5.

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.