Skip to content

Emit HTTP 308 for published slug aliases before HTML - #9

Merged
Chinmay-KB merged 1 commit into
mainfrom
cursor/http-308-slug-alias-redirect-8e2a
Aug 13, 2026
Merged

Emit HTTP 308 for published slug aliases before HTML#9
Chinmay-KB merged 1 commit into
mainfrom
cursor/http-308-slug-alias-redirect-8e2a

Conversation

@Chinmay-KB

Copy link
Copy Markdown
Owner

TL;DR

/g/microsoft-teams-tinder was HTTP 200 HTML titled “Not found” with noindex, then a streamed meta 308 to /g/microsoft-teams-tinder-1. Crawlers that only read the status line never saw a redirect.

This PR returns a real HTTP 308 with Location before any HTML, using the existing {slug} → lowest {slug}-{digits} alias lookup.

Root cause

The user’s guess was right.

  1. generateMetadata ran first. The unsuffixed slug is not a generation row, so it returned { title: "Not found", robots: { index: false, follow: false } }.
  2. Next then started the document (root layout + that metadata). Status line was already 200.
  3. The page’s permanentRedirect ran afterward. In a streaming context Next can only inject NEXT_REDIRECT;replace;…;308; plus <meta http-equiv="refresh"> — not a real status-line 308.

permanentRedirect in a Server Component cannot change headers after HTML has started.

What changed

  • src/proxy.ts — for /g/{slug} only, if the exact slug is not a published generation and a numeric alias exists, NextResponse.redirect(..., 308) runs before render. That is what curl -sI will see.
  • generateMetadata — same alias lookup before returning the not-found metadata, so we never commit “Not found” + noindex on an alias URL if render still happens.
  • Page permanentRedirect kept as a fallback, via a shared helper.
  • Alias lookup moved to src/lib/published-slug-alias.ts so proxy does not import the heavy generation module. Exact published slugs are not redirected (/g/foo stays when /g/foo is live, even if /g/foo-1 exists).

No OG, sitemap, cards, watermarks, or other site-health work.

How to confirm

curl -sI https://xbuildsy.com/g/microsoft-teams-tinder

Expect 308 (or 301) and Location containing /g/microsoft-teams-tinder-1, with no HTML body on that first response.

Locally: yarn test (98 passed, including new alias-redirect cases) and yarn lint (0 errors).

Open in Web Open in Cursor 

generateMetadata returned Not found + noindex and the root layout started
the document, so page-level permanentRedirect could only stream a meta
refresh. Look up the alias in generateMetadata and return NextResponse
308 from proxy before render.

Co-authored-by: Chinmay Kabi <chinmay@blend.to>
@supabase

supabase Bot commented Aug 13, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project bjsepxonrrnwwxaejkrv because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@Chinmay-KB
Chinmay-KB marked this pull request as ready for review August 13, 2026 14:06
@vercel

vercel Bot commented Aug 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
if-x-built-y Building Building Preview Aug 13, 2026 2:06pm

@Chinmay-KB
Chinmay-KB merged commit b735d8f into main Aug 13, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants