Let nginx support thinkphp URL rewrite and pathinfo

Source: Internet
Author: User
Allow Nginx to support thinkphp URL rewriting and PathInfo

Enable the thinkphp to operate correctly on Nginx.

Simply add the following information in the configuration file to allow Nginx to parse the thinkphp website correctly.

?

?

    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 $     ;        Set $path _info  ;      }        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;    }

Here, the requests under Project are forwarded to index.php for processing, that is, the single entry file for thinkphp, and then the request to the PHP file is given to fastcgi for processing, and the support for Path_info is added.

After restarting Nginx, Http://localhost/project/Index/insert, http://localhost/project/index.php/Index/delete such URLs can be correctly accessed.

One more place to note is that there is a space between the if and the parentheses in the Nginx configuration file, otherwise the unknown directive error will be reported.

?

Author: Playing upon? Posted on 2011-08-08 10:48? Original link

?

  • Related Article

    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.