// conf
server {
listen 80;
location /x {
root /templates;
index x.html;
}
location / {
root /templates;
index index.html;
}
}
//
// Folder
tempalets
| - index.html
| - x.html
我去 url domain.com,它會顯示index.html
但是,我去 url domain.com/x,它會顯示404 Not Found。
而且,我嘗試domain.com/x.html,它會顯示 x.html。
為什么 urldomain.com/x不顯示 x.html?
我怎么能去 urldomain.com/x并顯示 x.html?
我不希望.html在網址中出現。
uj5u.com熱心網友回復:
備選方案 1:
使用try_files。在它下面連接擴展名(.html),因此在請求/x它時首先檢查檔案是否/templates/x.html存在,然后/templates/x是 ,否則是404s。
server {
listen 80;
location / {
root /templates;
try_files $uri.html $uri =404;
index index.html;
}
}
備選方案 2:
上傳不帶擴展名的 HTML 檔案并將default_type (MIME) 設定為text/html.
default_type 'text/html';
https://blog.uidrafter.com/pretty-routes-for-static-html
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/525898.html
