How can I serve multiple projects under a single domain?

Vercel allows you to assign custom domains to your Projects directly from the dashboard, but a production domain can only be assigned to a single project to avoid disambiguity when resolving the domain.

What if you want to break up your application into multiple projects but serve them on different paths of a common base domain? Read on to learn how to achieve this.

Deploying Rewrite Rules

Instead of deploying a project with source code, you can deploy a standalone configuration file named vercel.json with rewrite rules that map source URL paths to any destination address. Your file may look something like the following:

{
  "rewrites": [
    {"source": "/:match*", "destination": "https://your-app.vercel.com/:match*"},
    {"source": "/admin/:match*", "destination": "https://admin-app.vercel.com/:match*"}
  ]
}

An example vercel.json file with rewrite rules.

Once you create a project with the configuration above, you can assign it a production domain. Any requests that match the rewrite rules, will be forwarded to the respective project.

Note:

The above scenario will result in three total Vercel projects. One for the rewrite rules, one for the root application, and another for the admin application.

Updated October 14th 2020