Skip to content

fix(pages): redirect /en, /index and the home slug to the home page - #120

Merged
sydevs-bot merged 10 commits into
mainfrom
claude/fix-114-index-redirect
Sep 21, 2026
Merged

sydevs-bot merged 10 commits into
mainfrom
claude/fix-114-index-redirect

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • /en 301'd to /index, a 200 duplicate of the home page whose own canonical is /. It now lands on /.
  • /index and /<locale>/index were reachable directly and served the home page again. Both now 301 to that locale's home URL.
  • The home document's own slug was a third URL for it, latent while that slug stays empty. /<homeSlug> now 302s to the locale's home URL.
  • No spec asserted a redirect target before, which is why this survived. Six new ones do.

Changes

  • lib/urls.ts — localeFromPath reports requestedIndex, so a consumer can tell a requested /index from the spelling the hook invents for a bare root. localePath holds the locale-prefix rule and localeUrl prefixes an origin to it. One private INDEX_PATH now answers for both requestedIndex and normalizeContentPath.
  • pages/+onBeforeRoute.ts — the de-localizing 301 runs its target through normalizeContentPath, and a requested /index 301s to localePath(locale, '/').
  • pages/[slug]/+data.ts — a request whose slug equals wm-web-config.homePage.slug 302s to localePath(locale, '/'). The routing hook cannot do this: the answer comes from the config, and +onBeforeRoute reads no CMS.
  • pages/[slug]/data.test.ts, pages/onBeforeRoute.test.ts — redirectOf catches the abort and reads _urlRedirect, so a spec can assert the target.
  • server/sitemap-routes.ts — a comment only. It claimed /<homeSlug> was a second 200; it is now a redirect, and the sitemap still omits it.
  • AGENTS.md — one bullet records that /index is routing-internal and that a redirect target goes through normalizeContentPath too.

Preview

https://claude-fix-114-index-redirect-wemeditate-web.contact-c66.workers.dev

Confirmed on that preview, reading %{http_code} and %{redirect_url}:

requested before preview now
/en /index 301 → /
/index 200 301 → /
/en/index /index 301 → /
/fr/index 200 301 → /fr
/pt-BR/index 200 301 → /pt-BR
/en/about /about 301 → /about, unchanged
/ 200 200, canonical /
/status/page, /about/index, /indexes route as slugs unchanged

/fr 404s on the preview. That is not this PR: the home document advertises only en, so no French home page exists to serve.

The /<homeSlug> redirect has no preview row: the live config's home document has an empty slug, so there is no URL to request. pages/[slug]/data.test.ts stands in for it, and reverting the check fails exactly its three target specs.

Test results

  • Lean gate: ✓ .claude/skills/pr-prep/check.sh — lint (0 errors), tsc --noEmit, 73 files / 697 tests
  • Targeted specs: 35 passed (lib/urls.test.ts, pages/onBeforeRoute.test.ts, pages/[slug]/data.test.ts)
  • Build: N/A — no build, bundler or Worker config changed

Notes for reviewer

  • One acceptance criterion is not met as written. The ticket asks that GET /en/ reach its destination in one hop. It takes two: Vike's normalizeUrlPathname 301s the trailing slash to /en before routing (renderPageServer.js:414), and /en then 301s to /. Same for /en/about/ → /en/about → /about. Both end on the right URL. Removing the first hop means changing Vike's trailingSlash config or adding Hono middleware, which is a separate decision. The ticket predicted one hop because it executed the hook in isolation, where that normalization does not run.
  • normalizeContentPath('/index/') used to return /index — it stripped the slash before its /index check, so a canonical on /index/ pointed at a URL this PR turns into a 301. It now returns /. That fix is inside this PR's own blast radius rather than a widening.
  • /<homeSlug> 302s, where /index 301s. /index is a routing spelling and permanent. A home slug is editor data: move homePage to another document and a cached 301 would leave the old slug unreachable for everyone who visited it first. Say so on the thread if you want 301 anyway.
  • Two review findings about components/atoms/Link/Link.tsx restating the locale-prefix rule and not normalizing its href are already filed as fix(links): Link and EmbedButton each restate the locale-prefix rule #115 and fix(urls): Link does not normalize its href, so a trailing slash spells a page twice #119. Not touched here.
  • Security review skipped. One server/ path now appears in the diff, matching securityReview.triggerPattern, but the change there is a comment.
Detail

Why the redirect lives in +data.ts and not the routing hook. +onBeforeRoute runs before any CMS read and would have to fetch wm-web-config on every request to know the home slug. +data.ts already awaits that config for the page it is about to render, so the check costs no extra read and cannot disagree with the value the render uses.

Why requestedIndex rather than a check in the hook. localeFromPath returns /index as pathWithoutLocale for both /fr and /fr/index, so the two are indistinguishable downstream. The first draft recovered the difference in the hook by slicing locale.length + 1 off the raw pathname — which restates the prefix shape localeFromPath's regex already matched, against this repo's lib/urls.ts convention. Computing the answer from the match that already exists removes the duplicate knowledge.

Why the smoke spec had to change. Its assertion was not.toMatch(/\/en(\/|$)/), which /index satisfies — it passed before and after the fix. It now reads new URL(res.location!).pathname.

How "reverting proves the spec" was checked. With pages/+onBeforeRoute.ts restored from origin/main and the new specs in place, exactly the three target specs fail and the ten pre-existing ones stay green. The same check on pages/[slug]/+data.ts: three of its five specs fail, two pass.

Why one spec lost the words "in one hop". It asserts /en, /en/ and /en/index, and /en/ reaches / in two. The name read as the ticket's unmet criterion, so a green spec could have been cited as proof it was met.

Rejected: exporting isIndexPath for the hook to call. It was a second definition of the /index spelling and disagreed with normalizeContentPath's. A module-private regex, consumed through requestedIndex and normalizeContentPath, leaves one.

Tool limitation: the sandbox's proxy blocks the CMS from the workerd runtime (Error: Network connection lost), so no page renders 200 locally. Every assertion above was taken from the deployed branch preview or a real dev server.

Closes #114

🤖 Written by the sydevs autonomous loop — see what this is

🤖 Generated with Claude Code

https://claude.ai/code/session_01Te95FaUSUTGcDQgX5dcw7C

`+onBeforeRoute` needs a redirect target as a path: `modifyUrl` rebuilds
the origin itself, and carrying the query across depends on that. The
locale prefix rule lived only inside `localeUrl`, which concatenates an
origin, so a consumer wanting the path alone had to restate the rule —
which the repo convention on `lib/urls.ts` forbids.

`localePath` holds the rule and `localeUrl` prefixes an origin to it.
Behaviour is unchanged, and the existing `localeUrl` specs still cover
both halves.

`isIndexPath` names the router's own `/index` spelling so a caller can
recognize one without spelling it a third time. It matches a trailing
slash too: `/index/` reaches `pages/[slug]/+route.ts` as slug `index`
just as `/index` does.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
`/en` 301'd to `/index`, which returns 200 and renders the home page —
whose own canonical is `/`. The site served the home page at two URLs and
pointed crawlers at the second one through a permanent redirect. `/index`
was also reachable directly, and once per locale as `/<locale>/index`.

`/index` is the spelling `+onBeforeRoute` invents so the router can match
the home page, and `lib/urls.ts` already owns the inverse. The redirect
now runs `pathWithoutLocale` through `normalizeContentPath`, and a
*requested* `/index` 301s to the home URL of its locale. Only the
requested path can tell the two apart: `localeFromPath` gives a bare
locale root the same `/index`, so the invented spelling can never be
mistaken for one a browser asked for. `urlLogical` keeps `/index`, since
`pages/[slug]/+route.ts` returns false for a bare `/`.

Confirmed against `pnpm dev`, reading `%{redirect_url}` and the followed
chain:

    /en            301 -> /              (was /index)
    /index         301 -> /              (was 200)
    /en/index      301 -> /              (was /index)
    /fr/index      301 -> /fr            (was 200)
    /pt-BR/index   301 -> /pt-BR         (was 200)
    /en/about?x=1  301 -> /about?x=1      unchanged, query preserved
    /status/page   404                    unchanged, not a locale prefix
    /about/index   404                    unchanged, /index only at the root

A trailing slash is Vike's, not ours: `normalizeUrlPathname` runs at
`renderPageServer.js:414`, before routing, so `/en/` 301s to `/en` and
`/en/about/` to `/en/about` before this hook sees either. Both then take
the redirect above, so `/en/` ends on `/` and `/en/about/` on `/about` in
two hops. `/index/` reaches `/` the same way. The ticket predicted one
hop for `/en/` because it executed the hook in isolation.

`pages/onBeforeRoute.test.ts` asserted only that `/en/about` throws, which
is why this survived: reverting the hook leaves the three new target
specs failing and the ten old ones green. The smoke spec asserted only
that the target no longer contains `/en`, which `/index` satisfied, so it
passed before and after the fix. It now reads the target's pathname.

Local rendering cannot reach the CMS from this sandbox, so `/` and `/fr`
answer 500 on the translations read. They route: a 500 from the data hook
is not the 404 a routing regression would give. The preview smoke run
covers the 200.

Refs #114

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
Three review findings converge on one edit. `+onBeforeRoute` re-derived the
locale-free path by slicing `locale.length + 1` off the raw pathname,
restating a prefix shape `localeFromPath`'s regex already matched — the
thing the `lib/urls.ts` convention exists to prevent. `localeFromPath`
now reports `requestedIndex`, computed from the match it already has, so
the consumer asks instead of re-parsing.

`isIndexPath` is gone with it. It had been a second definition of the
`/index` spelling, and it disagreed with the one in
`normalizeContentPath`: `normalizeContentPath('/index/')` stripped the
slash and returned `/index`, so `/en/index/` would have 301'd back onto
the spelling this branch redirects away from. One private `INDEX_PATH`
now answers for both, and `/index/` normalizes to `/`.

Also drop a duplicated `routeOf('/')` assertion the bare-root spec above
already makes, and a comment sentence narrating the `modifyUrl` call
beside it.

Re-verified on `pnpm dev`: every target in the previous commit is
unchanged, `/en/index/` now resolves to `/`, and `/indexes` still routes
as a slug rather than redirecting.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
The spec claimed `/about/` and `/about` both render, so the 301 must not
land on the duplicate. Vike's `normalizeUrlPathname` 301s the slash before
routing (`renderPageServer.js:414`), so no server request reaches this hook
carrying one. The spec still pins the hook's own answer, which is what it
should say.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
`docs/cloudflare-previews-ci.md` stated `/en` redirects to `/index`, under
a heading promising each fact matches the deployed Worker. The URL-spelling
convention in `AGENTS.md` named `localeUrl` and said nothing about the
`/index` spelling a consumer must not point at.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TrXcJDT5Est6CCMxmmv47v
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3f1d656
Status: ✅  Deploy successful!
Preview URL: https://63a85b89.wm-design.pages.dev
Branch Preview URL: https://claude-fix-114-index-redirec.wm-design.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web 3f1d656 Commit Preview URL

Branch Preview URL
Sep 18 2026, 11:21 PM

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 18, 2026
@sydevs-bot

sydevs-bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 23:16Z resolve-conflicts · attempt 1 · session · done
  • 23:16Z resolve-conflicts · attempt 1 · session
  • 23:07Z address-review · attempt 1 · session · done
  • 23:07Z address-review · attempt 1 · session
  • 19:19Z resolve-conflicts · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The diff is the size of #114. localePath is the only new export, and two callers need it because modifyUrl takes a pathname. On the branch preview /en, /en/index, /index and /fr/index each land in one hop, and / now canonicalises to itself. The unmet criterion — /en/ in one hop — is disclosed, and its argument holds. No contract surface is touched.

Findings — no blockers.

  • consider the "one hop" spec name outruns what the server does — pages/onBeforeRoute.test.ts:101
  • consider the other home-page twin, /<homeSlug>, stays open — pages/+onBeforeRoute.ts:18
  • consider the new guide bullet restates the one above it — AGENTS.md:183

Checked. Read whole: lib/urls.ts, the hook, both specs. Every consumer of the changed helpers: lib/head.tsx:183, lib/hreflang.ts:93, layouts/LayoutChrome.tsx:114, pages/+onCreatePageContext.server.ts:30. Probed 11 preview paths. /fr 404s because the home document advertises only en. #115 already covers Link and EmbedButton restating the prefix rule.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread pages/onBeforeRoute.test.ts Resolved
Comment thread pages/+onBeforeRoute.ts Resolved
Comment thread AGENTS.md Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 18, 2026
The spec name read as #114's unmet acceptance criterion. Vike 301s a
trailing slash before routing, so /en/ reaches its target in two hops
even though the hook answers in one. A later reader could have cited a
green spec as proof the criterion was met.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YTnExwDbTdUkh9ZHfUjtDH
The bullet above already states that normalizeContentPath undoes the
/index spelling. What it does not state is that a redirect target goes
through it too, and that a requested /index now 301s. The guide says it
stays short on purpose.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YTnExwDbTdUkh9ZHfUjtDH
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review on 26ef933. Lean gate green: lint, tsc --noEmit, 70 files / 665 tests.

Re-confirmed on the branch preview: /en, /en/index, /index → /; /fr/index → /fr; /pt-BR/index → /pt-BR; / still 200 and self-canonical.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 18, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 18, 2026 19:15
@sydevs-bot
sydevs-bot requested a review from Ardnived September 18, 2026 19:15
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 18, 2026
Both sides edited the `lib/urls.ts` bullet in AGENTS.md and the import line
in `lib/urls.test.ts`. Kept both: this branch's `requestedIndex`/`localePath`
rules alongside main's `isSafeHttpUrl`/`isSafeNavigationUrl` scheme rule.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01J1L7KdeDU1A7AeVeyexhL8
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main in. Two conflicts, both additive, both kept whole.

  • AGENTS.md — the lib/urls.ts bullet. This branch rewrote it for requestedIndex and localePath; main added the scheme rule (isSafeHttpUrl, isSafeNavigationUrl). The merged bullet carries both.
  • lib/urls.test.ts — the import line. Union of the two.

lib/urls.ts auto-merged: main's two scheme guards sit beside this branch's INDEX_PATH, requestedIndex and localePath, and nothing in either side redefines the other's.

Lean gate green on the merge: lint 0 errors, tsc --noEmit clean, 692 tests in 72 files.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 18, 2026
Comment thread pages/+onBeforeRoute.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 18, 2026
`wm-web-config.homePage` is served at `/`. `[slug]/+route.ts` also matched
that document's own slug, so an editor who filled the slug in would have
put one document at two 200 URLs — #114's shape at a second URL.

The check reads the config rather than trusting today's empty slug to hold,
and 302s rather than 301s: `/index` is a routing spelling and permanent,
while a `homePage` slug is editorial and a cached 301 would outlive a change
of home document.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Te95FaUSUTGcDQgX5dcw7C
@sydevs-bot sydevs-bot changed the title fix(pages): 301 /en and /index to the home page, not to its /index twin fix(pages): redirect /en, /index and the home slug to the home page Sep 18, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the review on 041fddc. Lean gate green: lint, tsc --noEmit, 73 files / 697 tests.

  • Adopted — the /<homeSlug> twin. pages/[slug]/+data.ts now redirects a request whose slug equals homePage.slug to that locale's home URL. Reverting the check fails exactly its three target specs.

It 302s where /index 301s: a home slug is editor data, and a cached 301 would outlive a move of homePage to another document. Say the word for 301.

⚠ The branch conflicts with main again — #118 landed on lib/urls.ts after the last merge. Not resolved here. GitHub schedules no CI run while a conflict stands.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 18, 2026
#118 split `localeUrl` into `localePath` + `localeUrl` and added
`isSitePath`. This branch had made the same split, for its own redirect
targets. Three files conflicted; both behaviours are kept.

- `lib/urls.ts` — the two splits are identical code, so main's version of
  that tail stands and `isSitePath` survives. This branch's `INDEX_PATH`
  and `requestedIndex` sit above it, untouched by either side.
- `lib/urls.test.ts` — the import list only.
- `AGENTS.md` — main's rewritten URL-spelling bullet, plus this branch's
  `requestedIndex` clause and its `/index is routing-internal` bullet.

Lean gate green after the merge: lint 0 errors, tsc clean, 74 files /
710 tests.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UEYDbxwjGimsypgzrvzJnQ
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main in. #118 had already split localeUrl into localePath + localeUrl — the same split this branch made for its redirect targets, so the two lib/urls.ts versions were identical code with different docs. Main's tail stands, which keeps isSitePath; this branch's INDEX_PATH and requestedIndex sit above it, untouched by either side.

AGENTS.md takes main's rewritten URL-spelling bullet plus this branch's requestedIndex clause and its /index bullet. lib/urls.test.ts was the import list only.

Lean gate green after the merge: lint 0 errors, tsc --noEmit clean, 74 files / 710 tests.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 18, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 21, 2026
Merged via the queue into main with commit cf7e088 Sep 21, 2026
17 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-114-index-redirect branch September 21, 2026 17:42
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(pages): /en redirects to /index, a 200 duplicate of the home page

3 participants