Skip to content

Instantly share code, notes, and snippets.

@Wellers0n
Created February 14, 2023 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wellers0n/b1c148fa47fa962c543f719ff260a249 to your computer and use it in GitHub Desktop.
Save Wellers0n/b1c148fa47fa962c543f719ff260a249 to your computer and use it in GitHub Desktop.
redirect url nextjs url from http to htttps
if (
PRODUCTION_ENV &&
request.headers.get("x-forwarded-proto") !== "https"
) {
const hostname = request.headers.get("host") || request.nextUrl.hostname;
return NextResponse.redirect(
`https://${hostname}${request.nextUrl.pathname}`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment