Skip to content

How to get the current URL / domain #16429

Answered by vvo
IRediTOTO asked this question in Help
Aug 21, 2020 · 10 comments · 23 replies
Discussion options

You must be logged in to vote

To anyone coming here to know how to have an env variable of NEXT_PUBLIC_URL containing:

Here's how to do it "the right way" as of September 2021.

For development:

# .env.development
NEXT_PUBLIC_URL=http://localhost:3000

For preview URLs:

# .env.production
NEXT_PUBLIC_URL=https://$NEXT_PUBLIC_VERCEL_URL

⚠️ Make sure to auto expose system env variables in Vercel env variable admin:

For production (yourdomain.com), create a new env variable on the Vercel dashboard, only for the production env:

I wish this were easier, and we could define the main domain for a proj…

Replies: 10 comments 23 replies

Comment options

You must be logged in to vote
3 replies
@zhenghaohe
Comment options

@samlak
Comment options

@Sammeeey
Comment options

Comment options

You must be logged in to vote
6 replies
@brunos3d
Comment options

@atawfique21
Comment options

@joelbiffin
Comment options

@WebDev-Akhil
Comment options

@Sammeeey
Comment options

Comment options

vvo
Sep 9, 2021
Collaborator

You must be logged in to vote
7 replies
@rennehir
Comment options

@TheYass1n
Comment options

@thevinci
Comment options

@diveddie
Comment options

@Leiloukou
Comment options

Answer selected by vvo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@jinsley8
Comment options

@WebDev-Akhil
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@CuriosBasant
Comment options

@crisu83
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Leiloukou
Comment options

@juliankoehn
Comment options

@Leiloukou
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet