Help with Next.js Rewrites for Multi-Domain Route Groups
Unanswered
Broad-snouted Caiman posted this in #help-forum
Broad-snouted CaimanOP
Hi everyone,
I'm trying to set up two domains (
My folder structure:
And my
### Questions:
1. Are the rewrite rules incorrect for handling multi-domain route groups?
2. Is there a recommended way to structure route groups when using domain-based routing?
3. Using a middleware for domain detection is another solution but that may become a performance issue.
Any guidance would be much appreciated! Thank you!
I'm trying to set up two domains (
site1.com
and site2.com
) in Next.js using the app router with route groups, but it is not working as expected.My folder structure:
app/
(site1)/
page.tsx
(site2)/
page.tsx
And my
rewrites.ts
: const rewrites = async () => {
return [
{
source: "/:path*",
has: [{ type: "host", value: "site1.com" }],
destination: "/(site1)/:path*",
},
{
source: "/:path*",
has: [{ type: "host", value: "site2.com" }],
destination: "/(site2)/:path*",
},
];
};
export default rewrites;
### Questions:
1. Are the rewrite rules incorrect for handling multi-domain route groups?
2. Is there a recommended way to structure route groups when using domain-based routing?
3. Using a middleware for domain detection is another solution but that may become a performance issue.
Any guidance would be much appreciated! Thank you!