← All Articles
3 min read

One Codebase, Two Domains: Serving a Blog Subdomain from the Same App

How blogs.itsmesujan.me works without a second project, second repo, or second deploy — just one proxy file.

Next.jsDNSVercelEdge
By Sujan

Why a Subdomain?

A blog deserves its own home, but spinning up a second Next.js project means double the repos, double the builds, and double the moving parts to monitor. Since the blog already lived in this app at /blog, I attached blogs.itsmesujan.me to the same Vercel project and let one deploy serve both domains.

DNS & Attaching the Domain

The domain is registered at Namecheap and its nameservers point there (not Vercel DNS). Attaching a new subdomain takes two steps: add blogs.itsmesujan.me in the Vercel project dashboard, then create a CNAME record at Namecheap pointing the subdomain to cname.vercel-dns.com. SSL is issued automatically by Vercel once the record propagates.

The Proxy Layer

Next.js 16 renamed middleware to proxy — same idea, better name. A single proxy.ts inspects the request host: main domain passes through untouched, the blog subdomain gets rewritten to the /blog routes. One file, one matcher, zero extra infrastructure.

tssnippet
export function proxy(request: NextRequest) {
  const host = (request.headers.get("host") ?? "")
    .toLowerCase().split(":")[0];

  if (host !== "blogs.itsmesujan.me")
    return NextResponse.next();

  const { pathname } = request.nextUrl;
  if (pathname === "/") {
    const url = request.nextUrl.clone();
    url.pathname = "/blog";
    return NextResponse.rewrite(url);
  }
  return NextResponse.next();
}

SEO Hygiene

Serving one page at two URLs invites duplicate-content penalties, so every blog page keeps its canonical tag pointing at itsmesujan.me/blog/*. The subdomain is a friendly mirror — search engines index the canonical home, visitors can land on either.