Using Vercel rewrites as a reverse proxy

Last updated:

|Edit this page

On this page

Vercel supports rewrites which we can use as a reverse proxy. Create a vercel.json file and add a rewrites object from the /ingest route to https://app.posthog.com or https://eu.posthog.com.

JSON
{
"rewrites": [
{
"source": "/ingest/:path*",
"destination": "https://app.posthog.com/:path*"
}
]
}

Some frameworks, like SvelteKit and Astro, require a hungrier regex pattern like:

JSON
{
"rewrites": [
{
"source": "/ingest/:path(.*)",
"destination": "https://app.posthog.com/:path*"
}
]
}

Note: Some frameworks, like T3 app, don't support Vercel rewrites well. If neither of these options work, we recommend trying another proxy method.

Once done, set the /ingest route of your domain as the API host in your PostHog initialization like this:

JavaScript
posthog.init('<ph_project_api_key>',
{
api_host: 'https://www.your-domain.com/ingest',
}
)

Once updated, deploy your changes on Vercel and check that PostHog requests are going to https://www.your-domain.com/ingest by checking the network tab on your domain.

Setup video

Questions?

Was this page useful?

Next article

Using Nuxt routeRules as a reverse proxy

Nuxt 3 uses Nitro under the hood, which provides the routeRules config that can be used to proxy requests from one route to another. To do this, add the following routeRules to your nuxt.config.ts file: Then configure the PostHog client to send requests via your new proxy:

Read next article