Paul LovellBook a call
Back to Blog
6 min readPaul Lovell

How to Host Shopify or Zendesk in a Subfolder Using Cloudflare Workers

"Our tech stack won't allow a subfolder" is usually solvable with a reverse proxy at the edge, not a platform change.

Technical SEOSite Architecture

One of the most common objections to consolidating content into subfolders is that the platform forces a subdomain — Shopify and Zendesk both default to their own subdomain-style URLs. A reverse proxy solves this without migrating platforms: intercept requests at the edge (Cloudflare Workers or NGINX) and route a subfolder path to the third-party origin, while the URL a user or crawler sees stays on your root domain.

User / Googlebot → request: example.com/shop/item-1
                          [Cloudflare Worker at the edge]
                     ┌──────────────┴──────────────┐
                path: /blog/*                 path: /shop/*
        forward to WordPress origin      forward to Shopify origin

The worker script

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const url = new URL(request.url)

  if (url.pathname.startsWith('/shop')) {
    const targetOrigin = 'https://your-store.myshopify.com'
    const newUrl = new URL(targetOrigin + url.pathname + url.search)

    const modifiedHeaders = new Headers(request.headers)
    modifiedHeaders.set('X-Forwarded-Host', url.hostname)
    modifiedHeaders.set('Host', 'your-store.myshopify.com')

    const modifiedRequest = new Request(newUrl, {
      method: request.method,
      headers: modifiedHeaders,
      body: request.body,
      redirect: 'manual'
    })

    return fetch(modifiedRequest)
  }

  return fetch(request) // default: pass through to the main site origin
}

What to check before calling it done

Bind the worker to the relevant route in Cloudflare (example.com/shop* → worker), then verify three things before treating the migration as complete:

  • Host header rewriting — confirm the third-party platform accepts the proxied request without returning a 403 or redirect loop
  • Canonical tags — pages served at example.com/shop/item-1 need self-referential canonicals, not ones pointing back at the myshopify.com origin
  • Asset routing — relative CSS/JS/image paths on the third-party platform often need their base URL updated to match the proxied subfolder path, or they'll 404
Paul Lovell

Written by

Paul Lovell

International SEO Consultant & Founder of Always Evolving SEO. 15+ years running technical audits, log-file analysis, and root-cause fixes for multimillion-dollar businesses — speaker at SMX London, Search & Content Summit, and SEMrush events.