Date: 2026-01-11 00:16
Summary: SEO-friendly server Accept-Language negotiation: temporary 302 from / to /en/ without static assets short-circuiting.
[question] 采用 curl -D - -H 'Accept: text/html' -H 'Accept-Language: en' http://127.0.0.1:8787/ 发现页面显示的是中文,而不是英文,按照符合seo的模式处理用户语言问题
[try to solve]
- Root cause: local/prod static assets could serve
public/index.htmlfor/before Worker language negotiation ran. - SEO-friendly approach:
- Stable URLs: Chinese default
/, English fixed/en/. - Prefer temporary redirects (302) for language preference, not permanent, so crawlers do not treat negotiation as a permanent rule.
- Add
Vary: Accept-Language, Accepton redirect responses to avoid cache mix-ups.
- Stable URLs: Chinese default
- Implementation:
- Build home HTML to
public/_pages/{lang}/index.htmlso/and/en/are not hit as static assets. - Worker handles
/and/en/explicitly:GET /+Accept: text/html: if Accept-Language prefers English → 302 to/en/; else return Chinese home.GET /en/: return English home.- When fetching
env.ASSETS, if assets normalizeindex.html→/, the Worker follows server-side and returns the final 200 so/_pages/...is not exposed.
- Build home HTML to
- Verify:
curl -D - -H 'Accept: text/html' -H 'Accept-Language: en' http://127.0.0.1:8787/→302 Location: /en/.curl -L ...ends on/en/.
[actions]
- Updated:
src/index.ts,scripts/build-site.mjs - Generated:
public/_pages/zh/index.html,public/_pages/en/index.html - Removed:
public/index.html,public/en/index.html