Contents
  1. Step 1: Assign the Old Subdomain as a Domain Alias
  2. Step 2: Add the Redirect Rule
  3. Why the Force Flag Is Required
  4. HTTP and HTTPS Rules
  5. Rule Processing Order
  6. Verify After Deploy
← All posts

Netlify Domain Redirects: Subdomain to Custom Domain

When migrating from a Netlify subdomain to a custom domain on the same site, a redirect rule alone is not enough. The subdomain must be assigned as a domain alias and the force flag is required.

When you move a Netlify site from yoursite.netlify.app to a custom domain, both URLs point to the same deploy. Without a redirect rule, visitors on the old subdomain stay there. This is the setup that makes the redirect work.

Step 1: Assign the Old Subdomain as a Domain Alias

Netlify only processes redirect rules for requests that reach your site. If yoursite.netlify.app is not assigned to the site, the redirect file is never consulted.

Go to Site settings → Domain management and keep yoursite.netlify.app listed as a domain alias alongside your custom domain. Do not remove it.

Step 2: Add the Redirect Rule

You have two options for where to put the rule.

public/_redirects (placed in your publish directory):

https://yoursite.netlify.app/*  https://yoursite.com/:splat  301!
http://yoursite.netlify.app/*   https://yoursite.com/:splat  301!

netlify.toml (at project root):

[[redirects]]
  from   = "https://yoursite.netlify.app/*"
  to     = "https://yoursite.com/:splat"
  status = 301
  force  = true

[[redirects]]
  from   = "http://yoursite.netlify.app/*"
  to     = "https://yoursite.com/:splat"
  status = 301
  force  = true

:splat captures everything after the * and appends it to the destination, so /about on the old domain lands on /about on the new one.

Why the Force Flag Is Required

Without force = true (or ! in _redirects), Netlify skips the rule if a matching file exists at the path. Since both domains serve the same build, every path resolves to a real file. The redirect silently does nothing. The force flag tells Netlify to redirect regardless.

HTTP and HTTPS Rules

Netlify subdomains always have HTTPS, so in practice only the HTTPS rule fires. The HTTP rule covers the edge case where a request arrives before any TLS upgrade, collapsing what would otherwise be two hops (HTTP → HTTPS on the subdomain, then subdomain → custom domain) into one.

Rule Processing Order

Rules are evaluated top-to-bottom. The first match wins. If you use both files, _redirects rules run before netlify.toml. Keep all redirect logic in one place to avoid ordering surprises.

Verify After Deploy

Browsers cache redirects. Use curl instead:

curl -I https://yoursite.netlify.app/

# Expect:
# HTTP/2 301
# location: https://yoursite.com/

curl -I https://yoursite.netlify.app/some/page
# location: https://yoursite.com/some/page

A 200 response means the force flag is missing or the domain alias is not configured. A location pointing back to the subdomain means a typo in the to value.

← All posts