Skip to content

feat(middleware): redirect production build URLs to canonical host - #19033

Merged
sfanahata merged 3 commits into
masterfrom
feat/canonical-production-redirect
Aug 13, 2026
Merged

feat(middleware): redirect production build URLs to canonical host#19033
sfanahata merged 3 commits into
masterfrom
feat/canonical-production-redirect

Conversation

@sfanahata

@sfanahata sfanahata commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

DESCRIBE YOUR PR

Problem: Contractors need to view PR previews, but with Vercel Deployment Protection off, generated production build URLs (for example, sentry-docs-<hash>.vercel.app) are also publicly accessible and indexable as a duplicate copy of the site.

Solution: In the existing middleware.ts, on production deployments only, 308-redirect GET and HEAD page requests whose host is not the canonical domain (docs.sentry.io / develop.sentry.dev) to that domain, preserving path and query.

  • Previews stay publicly accessible, so contractors can open preview links without secrets or share links.
  • Other methods and paths excluded by the middleware matcher, including API and static asset paths, are unaffected.
  • VERCEL_ENV is deliberately frozen into the bundle through next.config.ts; it is constant per deployment.
  • Complements the existing X-Robots-Tag: noindex on non-canonical hosts.

This is an SEO/canonicalization measure, not a security boundary. Existing production deployments will be deleted before protection is disabled because immutable older deployments do not contain this middleware.

Required: Turn off Vercel Standard Protection after this is deployed and old production deployments are deleted so previews are publicly reachable.

IS YOUR CHANGE URGENT?

  • Urgent: should merge asap

PRE-MERGE CHECKLIST

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

LEGAL BOILERPLATE

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

EXTRA RESOURCES

Option B for contractor preview access: instead of gating previews with
Vercel Deployment Protection, keep previews publicly accessible and lock
down only the generated *production* build URLs in middleware.

With Deployment Protection off, generated production URLs (e.g.
sentry-docs-<hash>.vercel.app) would be publicly accessible and indexable
as a separate copy of the site. This adds an early check in the existing
middleware that, on production deployments only, 308-redirects any request
whose host isn't the canonical domain (docs.sentry.io / develop.sentry.dev)
to that domain, preserving path and query.

- Preview deployments are untouched and stay publicly accessible, so
  contractors open PR previews with zero extra steps (no share links).
- Only GET requests are redirected; API/cron/webhook traffic is unaffected.
- VERCEL_ENV is inlined into the edge bundle via next.config.ts `env`
  (edge runtime can't read server env vars at request time).
- Complements the existing X-Robots-Tag: noindex on non-canonical hosts.

Requires turning OFF Vercel Standard Protection so previews are reachable.

Adds 7 middleware tests (21 total passing).
@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
develop-docs Ready Ready Preview Aug 12, 2026 10:21pm
sentry-docs Ready Ready Preview Aug 12, 2026 10:21pm

Request Review

@sfanahata sfanahata changed the title feat(middleware): redirect production build URLs to canonical host (Option B) feat(middleware): redirect production build URLs to canonical host Aug 12, 2026
Reword the next.config.ts and middleware.ts comments to describe the
VERCEL_ENV `env` entry as deliberate build-time freezing of a
per-deployment-constant value (following the DEVELOPER_DOCS convention),
rather than claiming the Edge runtime can't read server env vars. Vercel
exposes VERCEL_ENV at build and runtime when "Automatically expose System
Environment Variables" is enabled (the default); the freeze is a stability
choice, not a workaround. No behavior change.
@sfanahata
sfanahata merged commit a16dc14 into master Aug 13, 2026
24 checks passed
@sfanahata
sfanahata deleted the feat/canonical-production-redirect branch August 13, 2026 17:15
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