Skip to content

site: Redirect / to /docs on production deployments - #1955

Merged
marcleblanc2 merged 1 commit into
mainfrom
marc/site/redirect-root-to-docs
Sep 11, 2026
Merged

site: Redirect / to /docs on production deployments#1955
marcleblanc2 merged 1 commit into
mainfrom
marc/site/redirect-root-to-docs

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

Problem

Vercel's Slack and GitHub posts for a production deploy link "Visit" to the raw deployment URL, e.g. https://sourcegraph-docs-rmeucrf94-sourcegraph-f8c71130.vercel.app/. In production basePath is /docs, so nothing serves / and Vercel returns a 404. People click away thinking the deploy is broken.

deployment / /docs
preview 200 404
production 404 200

Change

When basePath is set, redirect //docs on the same host (basePath: false so the source matches the bare /). Same host, not sourcegraph.com/docs, so the visitor sees the exact deployment in the post rather than whatever is live. 307 so nothing gets cached if we change it later.

Preview deployments have no basePath, so redirects() returns [] and / keeps serving the homepage as today.

sourcegraph.com never proxies / to Vercel (only /docs/*), so the live site is unaffected.

Also hoisted the duplicated VERCEL_ENV ternary into one basePath const so basePath, NEXT_PUBLIC_DOCS_BASE_PATH, and the redirect can't drift.

Verified

VERCEL_ENV=production npx next dev:

/            307 → /docs
/docs        200
/docs/admin  200

Without VERCEL_ENV: / 200, /admin 200, no redirect.

Note

#1942 also adds a redirects key to next.config.js; whichever merges second will need a one-line conflict resolution (keep both entries).

With basePath=/docs nothing serves /, so the *.vercel.app deployment URL
that Vercel's Slack and GitHub posts link to returns a 404. Redirect it
to /docs on the same host, so the visitor sees that exact deployment.
Preview deployments (no basePath) are unchanged.

Amp-Thread-ID: https://ampcode.com/threads/T-01a092ad-91c8-772e-bcba-a44caabb1653
Co-authored-by: Amp <amp@ampcode.com>
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
sourcegraph-docs Ready Ready Preview Sep 11, 2026 11:20pm UTC

Request Review

@marcleblanc2
marcleblanc2 merged commit bfd1e61 into main Sep 11, 2026
4 checks passed
@marcleblanc2
marcleblanc2 deleted the marc/site/redirect-root-to-docs branch September 11, 2026 23:23
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