Next.js Discord

Discord Forum

Multi domain Setup

Answered
Broad-snouted Caiman posted this in #help-forum
Open in Discord
Broad-snouted CaimanOP
Hey folks,
What's the recommended way to have one NextJS Project and multiple sites?

website1.com
website2.com
website3.com

Should all point to one NextJS project.

I was planning to create routes /website1 /website2 etc. and then using rewrites to rewrite to the subpath depending on the host. Good or bad idea?
Answered by B33fb0n3
you got the right approach. Use the middleware to rewrite to the correct location in your app. A custom domain then works with a CNAME in the domain configuration. You can take a look at this great plattform starter project: https://github.com/vercel/platforms

And the middleware, that you mentioned: https://github.com/vercel/platforms/blob/main/middleware.ts
View full answer

7 Replies

Answer
@Broad-snouted Caiman solved?
@B33fb0n3 <@900030932617162793> solved?
Broad-snouted CaimanOP
Ah yes, I'll have to do a bit more testing, but seems to be working, thanks!
@Broad-snouted Caiman Ah yes, I'll have to do a bit more testing, but seems to be working, thanks!
that sounds great. Sure thing. Please mark solution