Prerequisite: Your primary domain (company.com) is hosted on and you are on the Mintlify Pro plan or above.

Quick Setup Guide

  1. Create a new Cloudflare Worker at Workers & Pages > Create application > Create worker

  2. Configure custom domain:

    • Go to Settings > Triggers
    • Click Add Custom Domain
    • Add your domain (with and without www.)
  3. Add the worker script:

    • Click Edit Code
    • Copy the script below
    • Replace [SUBDOMAIN] and [YOUR_DOMAIN] with your values
    • Click Deploy
addEventListener("fetch", (event) => {
  event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
  try {
    const urlObject = new URL(request.url);
    if (/^\/docs/.test(urlObject.pathname)) {
      const DOCS_URL = "[SUBDOMAIN].mintlify.dev";
      const CUSTOM_URL = "[YOUR_DOMAIN]";

      let url = new URL(request.url);
      url.hostname = DOCS_URL;

      let proxyRequest = new Request(url, request);
      proxyRequest.headers.set("Host", DOCS_URL);
      proxyRequest.headers.set("X-Forwarded-Host", CUSTOM_URL);
      proxyRequest.headers.set("X-Forwarded-Proto", "https");

      return await fetch(proxyRequest);
    }
  } catch (error) {
    return await fetch(request);
  }
}

Changes may take a few hours to propagate. For setup assistance, contact our support team.

Was this page helpful?