thinkpad win7 oem 讓Nginx支援ThinkPHP的URL重寫和PATHINFO的方法分享

來源:互聯網
上載者:User
網上搜了很多方法都不奏效,研究了一天,發現通過以下的配置可以完美支援 'URL_MODEL' => 2 的情況了

複製代碼 代碼如下:


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;
fastcgi_index index.php?IF_REWRITE=1;
include /APMServ/nginx/conf/fastcgi_params;
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錯誤。

以上就介紹了thinkpad win7 oem 讓Nginx支援ThinkPHP的URL重寫和PATHINFO的方法分享,包括了thinkpad win7 oem方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.