路由規則
網站是純靜態檔案,伺服器依照下面的順序尋找請求的路徑。
尋找順序
以請求 /about 為例:
- 同名檔案:網站根目錄下有沒有
about(沒有副檔名的檔案)。 - 同名 .html:有沒有
about.html。 - 目錄首頁:有沒有
about/index.html。有的話回應 301,跳轉到/about/,查詢參數會保留。 - 退回:回應 404;如果開啟了 SPA 退回,回應根目錄的
index.html。
首頁 / 直接回應 /index.html(或 /index.htm)。請求本身以 / 結尾時(例如 /about/),直接回應該目錄的 index.html,不會再跳轉。
範例
| 請求 | 網站裡的檔案 | 結果 |
|---|---|---|
/ | index.html | 200,index.html |
/about | about.html | 200,about.html |
/about | about/index.html | 301 到 /about/,然後 200 |
/about/ | about/index.html | 200,about/index.html |
/about | about.html 和 about/index.html 都有 | 200,about.html |
/docs/intro | docs/intro.html | 200 |
/docs/intro | docs/intro/index.html | 301 到 /docs/intro/ |
/missing | 無 | 404,或 SPA 退回 |
如果 about.html 和 about/index.html 同時存在,.html 優先。
目錄不會列出檔案清單。.js、.css、圖片、字型等靜態資源依原路徑直接回應。