Add assets.html_handling mode to *preserve .html filenames* while still serving /folder/ → /folder/index.html
#13220
Replies: 3 comments
-
|
Hi @kensukesaito, thank you very much for the issue 🙂 I have raised this with the team and we're generally open to this idea, the team is however quite busy and we unsure wether there is a significant demand for this. So for the time being we'll keep an eye on this issue, if more people comment / like this issue and we do get a signal that there is enough demand for this feature we'll happily implement it 😄 |
Beta Was this translation helpful? Give feedback.
-
|
Hi @dario-piotrowicz , Thanks for the quick follow-up and for raising this internally — appreciated! Just to add a bit more signal on why this would help:
Concretely, the proposed mode (e.g.,
Totally understand the team is busy. Even if this isn’t prioritized immediately, I hope the above shows there’s practical demand from folks migrating standard static sites to Workers. If others land here and share this need, please add a 👍/use-case so the team can gauge interest. |
Beta Was this translation helpful? Give feedback.
-
|
I have the same need: I’d like to migrate an existing site to Cloudflare and the redirections change existing URLs which is not good. I solved it as follows via a Worker, but a simpler approach would be nice to have: https://github.com/rauschma/cloudflare-worker-assets-demo |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
Today,
assets.html_handlingsupports four modes:"auto-trailing-slash"(default),"force-trailing-slash","drop-trailing-slash", and"none". In the default mode, a request to/file.htmlredirects to/file(the.htmlextension is dropped), while/folder/serves/folder/index.html. When"html_handling": "none",/file.htmlis served as-is but/folder/no longer maps to/folder/index.html(typically a 404 unless otherwise configured). (Cloudflare Docs)Problem
There is no mode that reproduces the “traditional” static web server behavior:
.htmlin the canonical URL (no forced extensionless redirect)./folder/as the canonical directory URL that serves/folder/index.html."auto-trailing-slash"removes.html, while"none"loses directory index behavior. (Cloudflare Docs)Proposal
Add a new
assets.html_handlingvalue, e.g."preserve-extension"(alternatives:"traditional","classic","keep-extension"), with rules:.htmlmatch: Serve without redirect./file.html→ 200/dist/file.html.htmlfile: Redirect to the.htmlfilename (to avoid duplicate content)./file→ 307/file.html/folder→ 307/folder/→ 200/dist/folder/index.htmlThis mirrors current behavior for directory indexes while preserving
.htmlas canonical—essentially the inverse of the current extension-dropping default. Existingassets.not_found_handlingsemantics remain unchanged. (Cloudflare Docs)Prior art / comparison
Major cloud providers’ static site hosting follows the traditional model by default:
/folder/ → /folder/index.html. S3 does not drop.htmlextensions automatically. (AWS Documentation)MainPageSuffixserves the matching index for a requested prefix (directory), e.g.,/folder/resolves to/folder/index.html, and.htmlfilenames are served as named. (Google Cloud).htmlstripping. (Microsoft Learn)Given this ecosystem baseline, Cloudflare Workers Static Assets would benefit from supporting the same traditional behavior out of the box. In fact, it may be more intuitive if this traditional behavior were the default, and the current
"auto-trailing-slash"(extension-dropping) behavior were opt-in via configuration. (Cloudflare Docs)Why this helps
.htmlextensions without forced redirects./folder/.run_worker_firstand custom routing just to emulate classical semantics.Thanks for considering this!
Beta Was this translation helpful? Give feedback.
All reactions