比方說,我有一個名爲careers.php
文件,我怎麼爲這個文件,當他們點擊進入http://example.com/careers
沒有兩個.html
和.php
文件與nginx的文件擴展名的鏈接?如何從nginx中的URL中刪除文件擴展名?
請注意,該解決方案必須考慮查詢字符串。例如,URL可能是
http://example.com/careers?lang=fr
。此外,我想解決方案也嘗試子目錄以及。例如;如果服務器上的我的文件夾結構是
/views/careers.php
,我想http://example.com/careers
仍然服務於/views/careers.php
。
我現在的配置如下所示:
server {
listen 80 default_server;
root /usr/share/nginx/landing-page;
index index.php index.html;
server_name example.com;
location/{
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
'try_files $ uril $ uri.php /views/$uri.php $ uri/= 404;'爲我的第二點工作?此外,這將允許查詢字符串? –
@EdwardMaxedon是的,查詢字符串將不受影響。對於第二點,考慮到'$ uri'將包含前導斜槓 – Vasfed
我現在已經注意到,而不是將文件作爲.php文件處理,它在我訪問該頁面時下載。 'location〜\ .php $'塊是否需要更新? –