讓Nginx支援ThinkPHP的URL重寫跟PATHINFO

來源:互聯網
上載者:User
讓Nginx支援ThinkPHP的URL重寫和PATHINFO

實現讓ThinkPHP在nginx上正確運行。

只需在設定檔中添加以下資訊,就能讓nginx正確解析ThinkPHP的網站。

?

?

    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;    }

這裡先把project下的請求都轉寄到index.php來處理,亦即ThinkPHP的單一入口檔案;然後把對php檔案的請求交給fastcgi來處理,並且添加對PATH_INFO的支援。

重啟Nginx以後,http://localhost/project/Index/insert, http://localhost/project/index.php/Index/delete 這樣的URL都可以正確訪問了。

還有一個地方需要注意的是,Nginx設定檔裡 if 和後面的括弧之間要有一個空格,不然會報unknown directive錯誤。

?

作者:?潺莪?發表於 2011-08-08 10:48?原文連結

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.