Let Nginx support ThinkPHP URL rewriting and PATHINFO-php Tutorial

Source: Internet
Author: User
Let Nginx support ThinkPHP URL rewriting and PATHINFO implementation so that ThinkPHP runs correctly on nginx. You only need to add the following information to the configuration file so that nginx can correctly parse ThinkPHP websites .?? Locationproject {indexindex. php; if (! -E $ request_filena: enable Nginx to support ThinkPHP URL rewriting and PATHINFO

To make ThinkPHP run correctly on nginx.

You only need to add the following information to the configuration file so that nginx can correctly parse ThinkPHP websites.

?

?

    location /project/    {      index  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;      include fastcgi.conf;      fastcgi_index  index.php?IF_REWRITE=1;      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.

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.

?

Author :? Or? Posted on? Original article link

?

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.