For other paths on subdomain
Open
Beginner friendly
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
- Access the main shop page:
shop1.localhost:3000(should work) - Access the thank you page:
shop1.localhost:3000/thank-you(should now work) - Verify other routes under the subdomain work as expected
Expected Behavior
shop1.localhost:3000→ routes to/s/shop1/page.tsxshop1.localhost:3000/thank-you→ routes to/s/shop1/thank-you.tsx
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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