Next.js Discord

Discord Forum

Revalidate rewrite domain

Answered
Bernese Mountain Dog posted this in #help-forum
Open in Discord
Avatar
Bernese Mountain DogOP
I am trying to revalidate page from api res.revalidate().
path is this: /pages/instalace/id/[uid]
I have domain that is rewrite to this dynamic path, but when revalidate that page it only update static content on the original domain. Second domain has still old content and dont update.


// ./middleware.ts
if (hostname === 'second.domain.tld') {
    const fullPath = `/instalace${path}`;
    return NextResponse.rewrite(new URL(fullPath, req.url));
  }
Answered by Bernese Mountain Dog
Solved!
Problem was in calling revalidate API route.
I have 2 domains: example.com -> main domain assigned to project, second sub.example.com -> rewrite for to path: /pages/instalace/id/[uid]
I was calling this revalidate api route: https://example.com/api/freelo/revalidate?token=123 --> this do revalidate page assinged to this domain, but not revalidate the page assigned to rewrite domain https://sub.example.com. So I changed the domain in calling of revalidate to this: https://sub.example.com/api/freelo/revalidate?token=123 --> and it works 🥳
View full answer

1 Reply

Avatar
Bernese Mountain DogOP
Solved!
Problem was in calling revalidate API route.
I have 2 domains: example.com -> main domain assigned to project, second sub.example.com -> rewrite for to path: /pages/instalace/id/[uid]
I was calling this revalidate api route: https://example.com/api/freelo/revalidate?token=123 --> this do revalidate page assinged to this domain, but not revalidate the page assigned to rewrite domain https://sub.example.com. So I changed the domain in calling of revalidate to this: https://sub.example.com/api/freelo/revalidate?token=123 --> and it works 🥳
Answer