Pointing Subdomain To A Next.js Page On Vercel

Viewed 1337

Is it possible to point a Vercel subdomain to a next.js page and not to a git separate branch?

I tried configuring a.subdomain.com on my Vercel domain subdomain.com and I just wanted to return a next.js page but Vercel insists I point to a git branch.

I could add a wildcard subdomain and handle routing within the frontend app, but I don't think routers like react-router offer a routing solution with subdomains because the subdomain is a limitation of the browser history api

What is the smart way to stand up a simple page under a subdomain in a next.js app?

1 Answers

You should use the rewrite or redirect as documented here: https://vercel.com/support/articles/can-i-redirect-from-a-subdomain-to-a-subpath

{
  "rewrites": [
    {
      "source": "/:path*",
      "has": [
        {
          "type": "host",
          "value": "a.domain.com"
        }
      ],
      "destination": "/a/:path*"
    }
  ]
}

Then create an a.domain.com record in vercel domain management like you were trying to do with no redirect. And set up your DNS with a cname pointing the subdomain to vercel.

Related