Multiple domains and languages on the same Next.js site

2021-04-0912:035911github.com

Hosting multiple domains on the same Next.js site (while maintaining multiple languages and SSG) - tomsoderlund/nextjs-multi-domain-locale

Multiple domains and languages on the same Next.js site

This is an example of hosting multiple domains on the same Next.js site (while maintaining multiple languages and static site generation (SSG)), using Next.js’ i18n system.

Demo

https://multi-domain-locale1.vercel.app/

Concept

  • Next.js’ i18n locale is used to determine the site.
  • Selecting a language is instead handled via a pseudoLocale prop (pages in a /[pseudoLocale] folder).
  • A redirect from / to /en.
  • TODO: Automatic language detection using the Accept-Language header.

See next.config.js for setup.


Page 2

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.


Read the original article

Comments

  • By dawnerd 2021-04-1015:471 reply

    I really wish next would just support multiple domains out of the box. I have two sites that share 99% of the same code but just need slightly different styles and endpoints.

    • By giovannibonetti 2021-04-1017:371 reply

      That can be dealed with proper CI tooling. In your build script you can create one folder for each website, tweak it as needed and deploy each of them independently.

      With Google Cloud Build you can even deploy them in parallel.

      • By dawnerd 2021-04-1018:51

        Yeah if been meaning to setup something like that. Was thinking a base docket image that has all the shared stuff and just mounting the different directories for each site to override. Just haven’t had time.

  • By gigel82 2021-04-1020:051 reply

    The biggest thing missing for i18n is `next export` support; that's the only way to get true SSR (static exports) for something like GitHub pages.

    It's a shame they haven't addressed that in months despite lots of folks asking for it.

    • By darkteflon 2021-04-110:00

      I ran into this (surprising) problem. Ended up having to shift my deployment from Netlify to Vercel itself to get around it.

  • By wdb 2021-04-1016:32

    Would this approach leak the other domains associated with the Next.js site?

HackerNews