Next.js Discord

Discord Forum

Wildcard subdomain + Internationalized routing - is this possible?

Unanswered
southclaws posted this in #help-forum
Open in Discord
I work on a product that has customer-based wildcard subdomains (customer1.app.com) and we need to integrate locales. At first I didn't want to use i18n routing because 1. we don't need /[lang]/ in the actual URL (don't care about SEO) and 2. it seemed a lot more complex but it seems to be impossible.

So I'm trying to get it done with Next.js' built in locale feature, but this is proving impossible too.

Mainly because, according to my assumption, Next.js looks at the first path segment automatically for req.nextUrl.locale but for wildcard subdomains also use this so.

When rewriting the URL, even if there's no path locale, I always get a 404 error.

Is this possible or should I just stop trying and figure something else out?

11 Replies

and do your i18n stuff for example setting a cookie with the desired language
set a custom header that is returned by the middleware
do your i18n stuff using the custom header
using the cookie do save the state for next visit
i was thinking publishing my way of doing it within a package
cause i use it for every of my projects
yeah but thats the logic behind it u can recreate it for yourself
Makes sense, I did try a cookie actually but it's only applying to my client components, server components are all remaining English as they seem to render before the root layout (which is the bit that does the cookie bit)
Thanks for confirming there is a way!
I'm going to bin SSR anyway as it's just causing problems tbh