Next.js Discord

Discord Forum

Question on redirecting on host match

Unanswered
Thai posted this in #help-forum
Open in Discord
ThaiOP
I'm curious how the has property works within NextJS redirects. We are trying to watch for a specific subdomain, and redirect to a path on our primary website.

It looks like the has property is how we would accomplish this: https://nextjs.org/docs/pages/api-reference/next-config-js/redirects#header-cookie-and-query-matching

What i'm not clear on is how the redirects can identify that it is coming from a specific host. Do we need to have the subdomain added as a domain within the same Vercel project alongside our primary domain?

For example, we have a subdomain learn.ourdomain.com . We need to redirect all paths to this subdomain to a specific page at ourdomain.com/learn.

Do we need the learn.ourdomain.com subdomain added as a domain within our ourdomain.com Vercel project for the has property redirect to work? If so, is there a way to test this locally?

0 Replies