How to support routing with multiple sub domains

I want to support multiple domains (e.g., app.example.com and admin.example.com). To clarify, I’m not trying to create a multi-tenancy app with custom domains.

These subdomains don’t share pages. app.example.com is for normal users and admin.example.com is for admins.

Should I create separate apps for each domain, or is there a way to assign separate domains for a set of routes inside a single Next.js project?

Hello :wave: I’m still looking for answers to this question. Let me know if you know anything about this

Hi, @hayata-suenaga! Welcome to the Vercel Community :smile:

Thanks for your patience :pray:

You could do this with some middleware magic, but seeing as the subdomains don’t share pages I’d actually suggest that you have two separate apps for each domain.

Creating separate applications for app.example.com and admin.example.com is better for separation of concerns, security, scalability, and routing simplicity, allowing for independent management and general maintenance of each subdomain.

Let us know how you get on! :smile:

Thank you for your advice, @pawlean!

I’ll go with creating separate Next.js applications for each subdomain. I’ll probably use Turborepo so that some code can be shared easily while separating these applications.

1 Like

Come back here if you have any questions :smile: Good luck!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.