{"id":739,"date":"2011-10-14T16:34:09","date_gmt":"2011-10-14T08:34:09","guid":{"rendered":"http:\/\/www.poloo.org\/?p=739"},"modified":"2011-10-14T16:34:09","modified_gmt":"2011-10-14T08:34:09","slug":"%e8%ae%a9nginx%e6%94%af%e6%8c%81thinkphp%e7%9a%84url%e9%87%8d%e5%86%99%e5%92%8cpathinfo","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=739","title":{"rendered":"\u8ba9Nginx\u652f\u6301ThinkPHP\u7684URL\u91cd\u5199\u548cPATHINFO"},"content":{"rendered":"<p>ThinkPHP\u652f\u6301\u901a\u8fc7PATHINFO\u548cURL rewrite\u7684\u65b9\u5f0f\u6765\u63d0\u4f9b\u53cb\u597d\u7684URL\uff0c\u53ea\u9700\u8981\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e &#8216;URL_MODEL&#8217; =&gt; 2 \u5373\u53ef\u3002\u5728Apache\u4e0b\u53ea\u9700\u8981\u5f00\u542fmod_rewrite\u6a21\u5757\u5c31\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u4e86\uff0c\u4f46\u662fNginx\u4e2d\u9ed8\u8ba4\u662f\u4e0d\u652f\u6301PATHINFO\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4fee\u6539 nginx.conf\u6587\u4ef6\u3002<\/p>\n<p>\u7f51\u4e0a\u641c\u4e86\u5f88\u591a\u65b9\u6cd5\u90fd\u4e0d\u594f\u6548\uff0c\u7814\u7a76\u4e86\u4e00\u5929\uff0c\u53d1\u73b0\u901a\u8fc7\u4ee5\u4e0b\u7684\u914d\u7f6e\u53ef\u4ee5\u5b8c\u7f8e\u652f\u6301 &#8216;URL_MODEL&#8217; =&gt; 2 \u7684\u60c5\u51b5\u4e86<\/p>\n<p><!--more--><\/p>\n<pre> 1 location \/project\/ {\r\n 2     index  index.php;\r\n 3     <span style=\"color: #0000ff;\">if<\/span> (!-e <span style=\"color: #800080;\">$request_filename<\/span>) { \r\n 4         rewrite  ^\/project\/(.*)$  \/project\/index.php\/$1  last;\r\n 5         <span style=\"color: #0000ff;\">break;<\/span>\r\n 6     }\r\n 7 }\r\n 8 \r\n 9 location ~ .+\\.php($|\/) {\r\n10     set <span style=\"color: #800080;\">$script $uri<\/span>;\r\n11     set <span style=\"color: #800080;\">$path_info<\/span>  \"\/\";\r\n12     <span style=\"color: #0000ff;\">if<\/span> (<span style=\"color: #800080;\">$uri<\/span> ~ \"^(.+\\.php)(\/.+)\") {\r\n13         set <span style=\"color: #800080;\">$script<\/span>     $1;\r\n14         set <span style=\"color: #800080;\">$path_info<\/span>  $2;\r\n15      }\r\n16          \r\n17     fastcgi_pass 127.0.0.1:9000;\r\n18     fastcgi_index  index.php?IF_REWRITE=1;\r\n19     <span style=\"color: #0000ff;\">include<\/span> \/APMServ\/nginx\/conf\/fastcgi_params;\r\n20     fastcgi_param PATH_INFO <span style=\"color: #800080;\">$path_info<\/span>;\r\n21     fastcgi_param SCRIPT_FILENAME  <span style=\"color: #800080;\">$document_root\/$script<\/span>;\r\n22     fastcgi_param SCRIPT_NAME <span style=\"color: #800080;\">$script<\/span>;\r\n23 }<\/pre>\n<p>\u8fd9\u91cc\u5148\u628aproject\u4e0b\u7684\u8bf7\u6c42\u90fd\u8f6c\u53d1\u5230index.php\u6765\u5904\u7406\uff0c\u4ea6\u5373ThinkPHP\u7684\u5355\u4e00\u5165\u53e3\u6587\u4ef6\uff1b\u7136\u540e\u628a\u5bf9php\u6587\u4ef6\u7684\u8bf7\u6c42\u4ea4\u7ed9fastcgi\u6765\u5904\u7406\uff0c\u5e76\u4e14\u6dfb\u52a0\u5bf9PATH_INFO\u7684\u652f\u6301\u3002<\/p>\n<p>\u91cd\u542fNginx\u4ee5\u540e\uff0chttp:\/\/localhost\/project\/Index\/insert, http:\/\/localhost\/project\/index.php\/Index\/delete \u8fd9\u6837\u7684URL\u90fd\u53ef\u4ee5\u6b63\u786e\u8bbf\u95ee\u4e86\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u5730\u65b9\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cNginx\u914d\u7f6e\u6587\u4ef6\u91cc if \u548c\u540e\u9762\u7684\u62ec\u53f7\u4e4b\u95f4\u8981\u6709\u4e00\u4e2a\u7a7a\u683c\uff0c\u4e0d\u7136\u4f1a\u62a5unknown directive\u9519\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ThinkPHP\u652f\u6301\u901a\u8fc7PATHINFO\u548cURL rewrite\u7684\u65b9&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[31,48,58,54,32,59],"class_list":["post-739","post","type-post","status-publish","format-standard","hentry","category-Php","tag-apache","tag-nginx","tag-rewrite","tag-thinkphp","tag-32","tag-59"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=739"}],"version-history":[{"count":1,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/739\/revisions"}],"predecessor-version":[{"id":740,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/739\/revisions\/740"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}