Multi domain Setup
Answered
Broad-snouted Caiman posted this in #help-forum
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?
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
And the middleware, that you mentioned: https://github.com/vercel/platforms/blob/main/middleware.ts
7 Replies
@Broad-snouted Caiman 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?
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
And the middleware, that you mentioned: https://github.com/vercel/platforms/blob/main/middleware.ts
Answer
@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
Broad-snouted CaimanOP
Thanks for the quick answer! Any advantages of using a middleware over setting rewrites in the Next config? Since it's not a multi tenancy app, hardcoding it wouldn't be an issue
@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