vercel / vercel/platforms

For other paths on subdomain

Open Beginner friendly
#460 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
6.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Root Cause

The middleware's routing logic only handles the root path for subdomains but doesn't properly rewrite other paths to include the shop slug.

Solution

Update the middleware to properly handle all paths under subdomains:

export async function middleware(request: NextRequest) {
  const { pathname } = request.nextUrl;
  const subdomain = extractSubdomain(request);

  if (subdomain) {
    // Block access to admin page from subdomains
    if (pathname.startsWith("/admin")) {
      return NextResponse.redirect(new URL("/", request.url));
    }

    // For the root path on a subdomain
    if (pathname === "/") {
      return NextResponse.rewrite(new URL(`/s/${subdomain}`, request.url));
    }

    // For other paths on subdomain (like /thank-you)
    return NextResponse.rewrite(new URL(`/s/${subdomain}${pathname}`, request.url));
  }

  return NextResponse.next();
}

Testing Steps

  1. Access the main shop page: shop1.localhost:3000 (should work)
  2. Access the thank you page: shop1.localhost:3000/thank-you (should now work)
  3. Verify other routes under the subdomain work as expected

Expected Behavior

  • shop1.localhost:3000 → routes to /s/shop1/page.tsx
  • shop1.localhost:3000/thank-you → routes to /s/shop1/thank-you.tsx

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Next.js middleware entry point and inspect how subdomain requests are rewritten. Test shop1.localhost:3000, /thank-you, and another subdomain route; done means root and non-root paths resolve under /s/shop1 while /admin redirects to /.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, typescript
Domain
full-stack, web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.