· By John Kavanagh

Redirect a Default Vercel Subdomain to Your Custom Domain

A photograph of a large white left-pointing arrow painted on a turquoise brick wall.
Image by Nick Fewings, licensed from Unsplash.

In Brief

Adding a custom domain in Vercel does not automatically remove the vercel.app hostname. Use a permanent redirect restricted to your production hostname; the vercel.json example below preserves paths and query strings whilst leaving distinct preview hosts alone. Keep the source‑host check, and test the destination too, so you don't create a redirect loop.

When launching a website on Vercel, setting up a custom domain is usually one of the final steps before you go live. However, what's not, perhaps, always obvious is that Vercel's default vercel.app subdomain carries on serving your website once your custom domain is connected.

For example, whilst building Linkudo, I set up linkudo.com as the primary domain, assuming that would be the only way to access the site. It became very clear very quickly that linkudo.vercel.app remained publicly accessible, effectively creating a duplicate version of the game.

Whilst this isn't necessarily a problem for everyone, search engines may choose a different canonical URL from the one you intended, and users can share the default address instead of your own. This isn't an automatic duplicate‑content penalty. A canonical tag is a useful signal about which URL you prefer, but it doesn't move visitors. If the default hostname should stop serving the site, a permanent redirect does both jobs. Keep the destination page's canonical pointing to your preferred custom‑domain URL too.


Option 1: Redirect Using Vercel's Dashboard

For possibly the quickest solution, look in Vercel's dashboard. If the default hostname offers a redirect control under Settings → Domains, you can handle it there:

  • Go to the Vercel Dashboard and open your project.
  • Navigate to Settings → Domains and find the default vercel.app hostname.
  • If Edit offers Redirect to, choose your custom domain and a permanent 308 redirect.
  • Save the changes, then check a nested URL with a query string using the commands below.

If that control isn't available for your default hostname, use Option 2. Vercel documents that configuration specifically for this job, and it makes the host, path, and destination explicit. There's no need to configure the same redirect in several places.


Option 2: Redirect Using vercel.json

If you'd rather define the redirect in code (perhaps for version control, or simply because you already have vercel.json set up), Vercel's hostname redirect example uses an explicit host condition. Add the rule to your existing redirects array, or use this file if you're starting from scratch:

  1. Open your project and create (or update) vercel.json in the root directory.
  2. Add the following:
{
  "redirects": [
    {
      "source": "/:path*",
      "has": [
        {
          "type": "host",
          "value": "yourproject\\.vercel\\.app"
        }
      ],
      "destination": "https://yourdomain.com/:path*",
      "permanent": true
    }
  ]
}

After that, all you need to do is deploy and build.

Once deployed, requests whose host is yourproject.vercel.app will be permanently redirected to yourdomain.com. Replace both with your actual hostnames, choosing the final HTTPS destination, including www if that's your canonical host. Requests already using the custom domain don't match, so the rule won't redirect back to itself.

There are a couple of small details doing useful work here:

  • The wildcard (:path*) keeps the requested path, and query parameters pass through unless you replace them in the destination. A visit to /articles/example?ref=test therefore reaches that same URL on the custom domain, rather than being dumped on the homepage.
  • The host value is a regular expression. The doubled backslashes in JSON make each dot literal. It matches the named production alias, not every vercel.app address, so distinct preview and deployment URLs remain outside this rule.
  • permanent: true produces a 308 response; permanent: false produces a temporary 307. Keep the permanent response for this change.

This matches a hostname, not an environment flag. Other deployment URLs remain accessible, so it isn't access protection.


Option 3: Redirect Using Next.js Middleware

If you're using Next.js (and if you're hosting with Vercel, I would say chances are very high that you are), then you could also implement this redirect at the application level using middleware, renamed Proxy in Next.js 16. Use this only when the application needs route‑specific flexibility, and retain the same explicit source‑host check. The example below uses Next.js 15's middleware.ts convention. For Next.js 16, follow the Proxy migration guide for proxy.ts, including the function rename and runtime requirements.

  1. If you don't already have one, create middleware.ts alongside app or pages, either in the project root or inside src, depending on your layout.
  2. Add this code, or merge the host check into your existing middleware:
import { NextResponse } from "next/server";

export function middleware(req: Request) {
  const url = new URL(req.url);

  if (url.hostname === "yourproject.vercel.app") {
    url.hostname = "yourdomain.com";
    return NextResponse.redirect(url.toString(), 308);
  }

  return NextResponse.next();
}

And then commit, deploy, and build.

Changing only url.hostname keeps the incoming pathname and query string intact. If you already restrict middleware with a matcher, make sure it includes every path you want redirected. For a straightforward hostname change, I'd still use the platform configuration above; Next.js also supports declarative redirects in next.config.js, without adding middleware just for this.


Check the Redirect

After deploying, replace the example host and path below with your own hostname and a real page. Vercel's has condition does not run in vercel dev, so check the deployed URL:

curl -I "https://yourproject.vercel.app/articles/example?ref=test"
curl -IL --max-redirs 5 "https://yourproject.vercel.app/articles/example?ref=test"

The first command checks one response. For Option 2 or 3, expect 308 and a Location header pointing to https://yourdomain.com/articles/example?ref=test. Check the hostname, path, and query string, not just the status code. Query parameters can carry search filters or tracking values that the destination still needs.

The second command follows the chain, showing each response, and stops after five redirects. Look for a successful final page, an unexpected detour through another hostname, or a repeated URL signalling a loop. A trailing‑slash or HTTP‑to‑HTTPS redirect may add a legitimate hop. Check the custom‑domain URL directly too, and confirm a preview URL still opens the preview. If the result differs, inspect earlier dashboard, firewall, or redirect rules before changing this one.


Wrapping Up

There are several different ways to manage redirects with Vercel, whether you prefer a dashboard setting, a JSON configuration, or a Next.js middleware solution.

  • For a quick fix, use the Vercel dashboard where that control is available (Option 1).
  • For a version‑controlled approach, use the vercel.json file (Option 2).
  • For more control, use Next.js middleware (Option 3).

If you're using Netlify, I've previously written a very similar article covering this same issue with the netlify.app default subdomains: "Redirect a Default Netlify Subdomain to Your Custom Domain".

Postscript

November 2026: I've revisited the hostname matching and added a quick way to check the result, including nested URLs and query strings. I've also clarified which preview URLs the redirect leaves alone, so testing a change doesn't unexpectedly send you back to production.

Need a senior engineer involved?

I can work directly in the codebase, review the architecture, or support the team through delivery when the work needs more than extra hands.