ThinkPHP 專案部署到 Nginx 發現不支援 PATHINFO,可透過 Nginx 重寫規則解決。
編輯 nginx.conf(通常在 /usr/local/nginx/conf/nginx.conf),於 location / 區塊加入:
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
此規則將請求轉發至 ThinkPHP 相容模式 URL,解決不支援 PATHINFO 的問題。
若 ThinkPHP 安裝在子目錄(如 youdomain),設定如下:
location /youdomain/ {
if (!-e $request_filename) {
rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last;
}
}
範例:
location /thinkphp/ {
if (!-e $request_filename) {
rewrite ^/thinkphp/(.*)$ /thinkphp/index.php?s=$1 last;
}
}
rewrite 語法:rewrite regex replacement flag,last 相當於 Apache 的 [L] 標記,表示重寫結束。