edge: a static folder asked for without its slash redirects to the slash form
/blog/post served blog/post/index.html with a 200, the same as /blog/post/, so analytics counted one page as two rows (Paul, 2026-10-29, on paulca.com) and the page's relative links resolved against its parent folder. Now the edge answers a 301 to "./post/" (relative, query kept), as GitHub Pages and Netlify do. A file is never redirected, a folder with no index.html stays a 404, a rewritten request is left alone, and a site whose _redirects names the path decides for itself, so a forced "/about/ /about 301!" cannot loop. Docs: docs/site/cli.md, under redirects for a static site. Census: serveTree body change, proposal census-proposal-static-dir-slash (no new read; the new branch only writes a Location and a status).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+113
−3
docs/site/cli.md+6 −0docs/superpowers/notes/census-proposal-static-dir-slash.md+19 −0internal/edge/redirects_test.go+57 −0internal/edge/static.go+21 −1internal/edge/static_cache_test.go+4 −2internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv+5 −0
CI cancelled — superseded by a newer push — run details
diff --git a/docs/site/cli.md b/docs/site/cli.md| index 62a213d65..3c6b02558 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -419,6 +419,12 @@ cannot use, and name the line. Netlify's conditions, such as `Country=`, and |
| proxying to another host are not supported. A file can have up to 2,000 |
| rules. The edge does not serve the `_redirects` file itself. |
| +A folder requested without its trailing slash, such as `/blog/post`, is |
| +redirected with a 301 to `/blog/post/`, where its `index.html` is served. |
| +Each page then has one address, and relative links in the page resolve |
| +against its own folder. If a `_redirects` rule names that path, the rule |
| +decides instead. |
| + |
| #### Two builds at once |
| When a new build reaches an awake instance, it starts beside the old one, |
diff --git a/docs/superpowers/notes/census-proposal-static-dir-slash.md b/docs/superpowers/notes/census-proposal-static-dir-slash.md| new file mode 100644 |
| index 000000000..fc357bd6d |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-static-dir-slash.md |
| @@ -0,0 +1,19 @@ |
| +# Census approval: static-dir-slash |
| + |
| +Ruling `census-ruling-static-dir-slash`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/edge/static.go` `staticSite.serveTree` | body | unchanged (2) | A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", or a _redirects rule names the path. It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the tree it already read. | |
| + |
| +Envelopes re-pinned: `internal/edge`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/edge/static.go` `staticSite.serveTree`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-static-redirects;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the same index-aware Stat lookup inside the extracted tree, now run at most twice (the request path, then once for a _redirects rewrite destination cleaned rooted inside the same tree); the Open moves to serveFile; the _redirects file itself is never answered; no root decision;rev3=census-ruling-edge-protection-2;basis=consults the edge protection matcher (internal/edgeguard, pure and in-memory) on the request path (probe tier, only when no file and no _redirects rule names it) and on a rewrite target (hard tier, only when the file is there), and may answer the guard's 404 block page through guardDecide before a redirect or the rewritten file; the _redirects lookup gains an in-memory names check; the same index-aware Stat lookups inside the extracted tree, unchanged; no read added |
| + |
| +Seal: `1de834976c615fed28567ca0a9ae7526eaa35341e07898feb112f4e1b0ddee8d` → `2c784a68ded2871314eb7aaa1689342d94b944a4f19b91a31b35085e4190ed00`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/edge/redirects_test.go b/internal/edge/redirects_test.go| index 8495a3537..8e026e106 100644 |
| --- a/internal/edge/redirects_test.go |
| +++ b/internal/edge/redirects_test.go |
| @@ -317,3 +317,60 @@ func TestStaticWithoutRedirectsIsUnchanged(t *testing.T) { |
| t.Fatalf("GET under a file = %d, want 404", got.code) |
| } |
| } |
| + |
| +// A directory asked for without its trailing slash is sent to the slash |
| +// form, as GitHub Pages and Netlify do: one URL per page (analytics counted |
| +// /blog/post and /blog/post/ as two pages), and the page's relative links |
| +// resolve against its own directory. The Location is relative, so it |
| +// survives any prefix the request arrived under, and keeps the query. |
| +func TestStaticDirectoryWithoutSlashRedirects(t *testing.T) { |
| + srv, c := redirectFixture(t, "") |
| + const host = "site.example.com" |
| + for _, tc := range []struct { |
| + path, location string |
| + code int |
| + body string |
| + }{ |
| + {"/about", "./about/", 301, ""}, |
| + {"/about?ref=feed", "./about/?ref=feed", 301, ""}, |
| + {"/about/", "", 200, "about"}, |
| + {"/docs", "", 404, ""}, // a directory with no index.html stays a 404 |
| + {"/style.css", "", 200, "body{}"}, // a file is never redirected |
| + {"/", "", 200, "home"}, |
| + } { |
| + got := fetch(t, c, "GET", srv.URL, host, tc.path) |
| + if got.code != tc.code || got.location != tc.location || (tc.body != "" && got.body != tc.body) { |
| + t.Errorf("GET %s = %d %q %q, want %d %q %q", tc.path, got.code, got.location, got.body, tc.code, tc.location, tc.body) |
| + } |
| + } |
| + if got := fetch(t, c, "HEAD", srv.URL, host, "/about"); got.code != 301 || got.location != "./about/" { |
| + t.Errorf("HEAD /about = %d %q, want 301 ./about/", got.code, got.location) |
| + } |
| + // The redirect resolves to the slash form, which serves the page. |
| + follow := &http.Client{} |
| + req, _ := http.NewRequest("GET", srv.URL+"/about", nil) |
| + req.Host = host |
| + resp, err := follow.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + b, _ := io.ReadAll(resp.Body) |
| + resp.Body.Close() |
| + if resp.StatusCode != 200 || string(b) != "about" || resp.Request.URL.Path != "/about/" { |
| + t.Errorf("following /about ended at %s = %d %q, want /about/ 200 \"about\"", resp.Request.URL.Path, resp.StatusCode, b) |
| + } |
| +} |
| + |
| +// A site whose _redirects names the directory has said what it wants there. |
| +// A forced rule sending /about/ to /about would otherwise loop with this |
| +// redirect, so the slash redirect stands aside and /about serves the page. |
| +func TestStaticDirectorySlashRedirectYieldsToTheSitesRules(t *testing.T) { |
| + srv, c := redirectFixture(t, "/about/ /about 301!\n") |
| + const host = "site.example.com" |
| + if got := fetch(t, c, "GET", srv.URL, host, "/about/"); got.code != 301 || got.location != "/about" { |
| + t.Fatalf("GET /about/ = %d %q, want the site's 301 to /about", got.code, got.location) |
| + } |
| + if got := fetch(t, c, "GET", srv.URL, host, "/about"); got.code != 200 || got.body != "about" { |
| + t.Fatalf("GET /about = %d %q %q, want 200 \"about\" (no slash redirect, no loop)", got.code, got.location, got.body) |
| + } |
| +} |
diff --git a/internal/edge/static.go b/internal/edge/static.go| index b1f783f89..0a9a03ac5 100644 |
| --- a/internal/edge/static.go |
| +++ b/internal/edge/static.go |
| @@ -481,7 +481,8 @@ func (s *staticSite) serveTree(tree servedTree, w http.ResponseWriter, r *http.R |
| for { |
| fp := filepath.Join(tree.dir, filepath.FromSlash(p)) |
| fi, err := os.Stat(fp) |
| - if err == nil && fi.IsDir() { |
| + isDir := err == nil && fi.IsDir() |
| + if isDir { |
| fp = filepath.Join(fp, "index.html") |
| fi, err = os.Stat(fp) |
| } |
| @@ -535,6 +536,25 @@ func (s *staticSite) serveTree(tree servedTree, w http.ResponseWriter, r *http.R |
| http.NotFound(w, r) |
| return |
| } |
| + if !rewritten && isDir && r.URL.Path != "" && !strings.HasSuffix(r.URL.Path, "/") && |
| + !tree.redirects.names(requestHost(r.Host), p) { |
| + // A directory asked for without its trailing slash goes to the |
| + // slash form, as GitHub Pages and Netlify send it: one URL per |
| + // page, so analytics does not count /blog/post and /blog/post/ |
| + // as two, and the page's relative links resolve against its own |
| + // directory rather than its parent. Relative, so it survives any |
| + // prefix the request arrived under; "./" so a first segment with |
| + // a colon is never read as a scheme. A site whose _redirects |
| + // names this path has said what it wants here (a forced |
| + // "/about/ /about 301!" would otherwise loop), so it is left be. |
| + loc := "./" + path.Base(r.URL.EscapedPath()) + "/" |
| + if q := r.URL.RawQuery; q != "" { |
| + loc += "?" + q |
| + } |
| + w.Header().Set("Location", loc) |
| + w.WriteHeader(http.StatusMovedPermanently) |
| + return |
| + } |
| if !rewritten && strings.HasSuffix(r.URL.Path, "/index.html") { |
| // Relative, as ServeFile wrote it, so it survives any prefix the |
| // request arrived under. |
diff --git a/internal/edge/static_cache_test.go b/internal/edge/static_cache_test.go| index 04b23a846..ccdbd09d9 100644 |
| --- a/internal/edge/static_cache_test.go |
| +++ b/internal/edge/static_cache_test.go |
| @@ -328,9 +328,11 @@ func TestStaticTagCoversTheContentType(t *testing.T) { |
| if err := release.Promote(context.Background(), store, priv, release.OpsAccount, "site", "canary/x", "v3"); err != nil { |
| t.Fatalf("Promote v3: %v", err) |
| } |
| - resp, body := reqStatic(t, "GET", srv.URL, "/about", map[string]string{"If-None-Match": plainTag}) |
| + // Asked for as /about/: /about is now a directory, which redirects to its |
| + // slash form (TestStaticDirectoryWithoutSlashRedirects). |
| + resp, body := reqStatic(t, "GET", srv.URL, "/about/", map[string]string{"If-None-Match": plainTag}) |
| if resp.StatusCode != http.StatusOK || body != same || !strings.HasPrefix(resp.Header.Get("Content-Type"), "text/html") { |
| - t.Fatalf("revalidating /about after it became HTML = %d %q; want a text/html 200", resp.StatusCode, resp.Header.Get("Content-Type")) |
| + t.Fatalf("revalidating /about/ after it became HTML = %d %q; want a text/html 200", resp.StatusCode, resp.Header.Get("Content-Type")) |
| } |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index b7a7fc247..a88c5d0bd 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -30,3 +30,4 @@ plan14-root-reads-rootfs-apps-3-workers.tsv 862d7383ad60d522d6b16f8a545c4cfa37de |
| plan14-root-reads-fresh-box-446.tsv 862d7383ad60d522d6b16f8a545c4cfa37de3d2cc1ba83fec1aff3825a0fe8ab |
| plan14-root-reads-rootfs-apps-4.tsv e085917e271ee26877974461133f393ccc5d63add91d7aad2afe10b30977914e |
| plan14-root-reads-regional-domains-447.tsv 1de834976c615fed28567ca0a9ae7526eaa35341e07898feb112f4e1b0ddee8d |
| +plan14-root-reads-static-dir-slash.tsv 2c784a68ded2871314eb7aaa1689342d94b944a4f19b91a31b35085e4190ed00 |
diff --git a/internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv b/internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv| new file mode 100644 |
| index 000000000..083b02733 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv |
| @@ -0,0 +1,5 @@ |
| +# Census overlay static-dir-slash, written by census-propose (#369). census-ruling-static-dir-slash, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-static-dir-slash.md. |
| +# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy 1459647714751786c5eb8c06e71d1c1a48fad424e5d59fa1a17a37907ab80e8d internal/edge/static.go staticSite.serveTree legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-static-redirects;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the same index-aware Stat lookup inside the extracted tree, now run at most twice (the request path, then once for a _redirects rewrite destination cleaned rooted inside the same tree); the Open moves to serveFile; the _redirects file itself is never answered; no root decision;rev3=census-ruling-edge-protection-2;basis=consults the edge protection matcher (internal/edgeguard, pure and in-memory) on the request path (probe tier, only when no file and no _redirects rule names it) and on a rewrite target (hard tier, only when the file is there), and may answer the guard's 404 block page through guardDecide before a redirect or the rewritten file; the _redirects lookup gains an in-memory names check; the same index-aware Stat lookups inside the extracted tree, unchanged; no read added;rev3=census-ruling-static-dir-slash;basis=A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", or a _redirects rule names the path. It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the tree it already read. file:Stat@1081,file:Stat@967 a7a576fcdc24947cbb3af8cf9b63992b63ece193c017faf099ab4a222ee2773e |
| +internal/edge/static.go staticSite.serveTree legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-static-redirects;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the same index-aware Stat lookup inside the extracted tree, now run at most twice (the request path, then once for a _redirects rewrite destination cleaned rooted inside the same tree); the Open moves to serveFile; the _redirects file itself is never answered; no root decision;rev3=census-ruling-edge-protection-2;basis=consults the edge protection matcher (internal/edgeguard, pure and in-memory) on the request path (probe tier, only when no file and no _redirects rule names it) and on a rewrite target (hard tier, only when the file is there), and may answer the guard's 404 block page through guardDecide before a redirect or the rewritten file; the _redirects lookup gains an in-memory names check; the same index-aware Stat lookups inside the extracted tree, unchanged; no read added;rev3=census-ruling-static-dir-slash;basis=A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", or a _redirects rule names the path. It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the tree it already read. file:Stat@1081,file:Stat@967 a7a576fcdc24947cbb3af8cf9b63992b63ece193c017faf099ab4a222ee2773e |
| +@coverage internal/edge afd15ca8d48fd3c4b4555889b12f4743298ba26b26b8b2ae244fd9109b8c34fa |