跳到主要内容

路由规则

站点是纯静态文件,服务器按下面的顺序查找请求的路径。

查找顺序​

以请求 /about 为例:

  1. 同名文件:站点根目录下有没有 about(没有扩展名的文件)。
  2. 同名 .html:有没有 about.html。
  3. 目录首页:有没有 about/index.html。有的话返回 301,跳转到 /about/,查询参数会保留。
  4. 回退:返回 404;如果开启了 SPA 回退,返回根目录的 index.html。

首页 / 直接返回 /index.html(或 /index.htm)。请求本身以 / 结尾时(比如 /about/),直接返回该目录的 index.html,不会再跳转。

例子​

请求站点里的文件结果
/index.html200,index.html
/aboutabout.html200,about.html
/aboutabout/index.html301 到 /about/,然后 200
/about/about/index.html200,about/index.html
/aboutabout.html 和 about/index.html 都有200,about.html
/docs/introdocs/intro.html200
/docs/introdocs/intro/index.html301 到 /docs/intro/
/missing无404,或 SPA 回退

如果 about.html 和 about/index.html 同时存在,.html 优先。

目录不会列出文件列表。.js、.css、图片、字体等静态资源按原路径直接返回。


延伸:自定义 404、站点配置