先说结论
EdgeOne Pages 和 Cloudflare 不一样:
- 不会自动把
/about映射到about.html; - 路径以
/结尾时,会自动返回该目录下的index.html; - 目录地址不带结尾斜杠时,可能直接 404;
- 想用扁平
.html文件实现干净地址,必须在edgeone.json里逐条写rewrites。
方案 A:目录式输出(推荐)
每个页面一个目录,入口是 index.html,站内链接带结尾斜杠:
/
├─ index.html → /
├─ about/index.html → /about/
├─ products/index.html → /products/
├─ blog/post/index.html → /blog/post/
└─ 404.html链接写法:/about/、/products/、/blog/post/。不需要任何配置,层数也不受规则数量限制。
方案 B:扁平 .html + rewrites
如果坚持 about.html 这种扁平结构,在项目根目录放 edgeone.json:
{
"rewrites": [
{ "source": "/about", "destination": "/about.html" },
{ "source": "/products", "destination": "/products.html" },
{ "source": "/contact", "destination": "/contact.html" }
]
}注意:
- 字段是
source/destination; - 每条规则只匹配一层路径,多级目录要逐层写;
- 最多 100 条规则;
- 非 ASCII 路径需要 URL 编码;
- 单页应用才使用
{ "source": "/*", "destination": "/index.html" },多页站点不要加。
常见坑
- 链接写
/about,但文件是about.html且没有 rewrite:404。 - 目录式输出链接漏了结尾
/:可能 404。 - 扁平结构页面一多就超过 100 条规则:改用目录式输出。
- 多页站点误加 SPA 回退:所有地址都变成首页。
- 文件名大小写不一致。
检查清单
- [ ] 二选一:目录式
/about/,或扁平.html+ rewrites - [ ] 所有站内链接与所选方案一致
- [ ] 目录式链接都带结尾
/ - [ ] 扁平结构没有超过 100 条规则
- [ ] 多页站点没有 SPA 回退
- [ ] 有
404.html
可直接复制的提示词
你是一名前端工程师,要为【品牌名 / 业务】生成一个可直接部署到腾讯云 EdgeOne Pages 的静态多页网站。
硬性规范:
1. 使用目录式输出:根目录 index.html;每个页面一个目录并以 index.html 作为入口,例如 about/index.html、products/index.html、blog/post/index.html;资源放在 assets/。
2. 所有站内链接写带结尾斜杠的根相对路径:/、/about/、/products/、/blog/post/;禁止写 about.html,禁止写不带斜杠的 /about,禁止使用 ../。
3. canonical、og:url、sitemap.xml、JSON-LD 使用同样的带斜杠地址。
4. 文件名只用小写字母、数字和连字符。
5. 不依赖服务端路由、Node、数据库或构建工具;只用 HTML、CSS 和原生 JavaScript。
6. 提供 404.html;多页站点不要添加 SPA 回退规则。
7. 如果必须使用扁平 .html 文件,请同时输出 edgeone.json,为每个页面配置 rewrites,并说明规则数量上限。
8. 输出完整文件清单和每个文件的完整内容,不要省略。
9. 页面正文使用【中文 / 英文】。