Skip to main content
New Pages Integration

Cloudflare Workers reverse proxy for Similar AI new pages

Serve Similar AI-generated pages under your own domain using a Cloudflare Workers reverse proxy. This guide walks through creating the Worker, deploying it, and wiring up a route so traffic flows through seamlessly.

Robin AllensonBy Robin Allenson, CEO & Co-Founder

Before you start

  • 1.Your domain is already managed through Cloudflare (DNS proxied through Cloudflare).
  • 2.Similar AI has provisioned your subdomain, e.g. yourstore.page.similar.ai. If you have not received this, contact your Similar AI account manager.
  • 3.You have completed the new page onboarding checklist.

Step 1 - Create a Cloudflare Worker

  1. a.Go to dash.cloudflare.com and navigate to Workers & Pages.
  2. b.Click Create Application and set a name, for example reverse-proxy.
  3. c.Click Edit Code and paste the following script. Replace client.com with your domain and client.page.similar.ai with the subdomain Similar AI provisioned for you.
async function handleRequest(request) {
  let url = new URL(request.url)
  let target = ORIGINS[url.hostname]
  if (target) {
      url.hostname = target
      return fetch(url, request)
  }
  return fetch(request)
}
addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

const ORIGINS = {
  'client.com': 'client.page.similar.ai',
}

Double-check that you replaced client.com with your actual domain in the ORIGINS object before deploying.

d.Click Deploy.

Step 2 - Add a Workers Route

  1. a.In the Cloudflare dashboard, go to Workers Routes and click Add route.
  2. b.In the Route field, enter your domain followed by the folder path you want to use, for example: yourstore.com/s/*. The trailing wildcard ensures all paths under that folder are proxied.
  3. c.In the Worker dropdown, select the reverse-proxy worker you created in Step 1.
  4. d.Click Save.

How the proxy works

When a visitor requests a URL that matches your Workers Route (e.g. yourstore.com/s/blue-widgets), Cloudflare intercepts the request before it reaches your origin server. The Worker rewrites the hostname to your Similar AI subdomain and forwards the request. The response is returned to the visitor as if the page lived on your own domain.

This means your visitors see your domain in the address bar, search engines index the pages under your domain, and you keep full control of DNS and SSL through Cloudflare.

1

Request arrives

Visitor hits yourstore.com/s/blue-widgets

2

Worker rewrites hostname

Cloudflare forwards to yourstore.page.similar.ai

3

Page served under your domain

Visitor sees your URL, search engines index your domain

Not using Cloudflare?

If your site is not behind Cloudflare, you can achieve the same result with an Nginx reverse proxy. See the Nginx reverse proxy integration guide for instructions.

Ready to serve new pages under your domain?

Get started with Similar AI new pages. We handle page creation, content, and internal linking - you control how pages are served on your site.