Using Netlify redirects as a reverse proxy

Last updated:

Netlify supports redirects and rewrites which we can use as a reverse proxy from an /ingest route to https://app.posthog.com or https://eu.posthog.com. In your netlify.toml file, add a redirect like this:

JavaScript
[[redirects]]
from = "/ingest/*"
to = "https://app.posthog.com/:splat"
host = "app.posthog.com"
status = 200
force = true

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 Netlify and check that PostHog requests are going to https://www.your-domain.com/ingest by checking the network tab on your domain.

Questions?

Was this page useful?

Next article

Using Vercel rewrites as a reverse proxy

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 . Once done, set the /ingest route of your domain as the API host in your PostHog initialization like this: 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

Read next article