路由规则
站点是纯静态文件,服务器按下面的顺序查找请求的路径。
查找顺序
以请求 /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、图片、字体等静态资源按原路径直接返回。