改善
Kaizen  · Today I Learned by Ville Säävuori

Migrating Vercel Project To Another On A Different Domain

It’s very easy to add a custom domain to a Vercel project. It’s also easy to redirect the default Vercel project URL to another domain or set up separate domains for staging and production. But I had to do some digging to be able to migrate my project from domain foo to point to a new project on domain bar.

The Problem

Back in January I created a simple dashboard for following my exercises and put it on health.unessa.net. The project has kept growing and growing, and eventually I decided to convert it to a full-blown blog. The blog needed a proper name and I wanted to change the domain to match it as well. I put the new project in a new repository and published it at tuonela.unessa.net. Now I had a problem; how do I redirect the (almost zero) traffic from the old project to the new without breaking the old URLs?

The Solution

Prerequisites: two different Vercel projects w/ custom domains configured.

  1. Remove the old custom domain from the original Vercel project.
  2. Add the old custom domain to the new Vercel project.
  3. Configure a 301 redirect from the old domain to the new domain in the new Vercel project.
  4. Profit!1

This is a proper 301 redirect setup which respects your URLs as well. (So all your old URLs from the old domain are redirected to the same path on the new domain.)