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

Setup Steps

  1. Create a Cloudflare Worker by going to Workers & Pages > Create application > Create worker

  2. Add your custom domain:

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

    • Click Edit Code
    • Copy the script below
    • Replace [SUBDOMAIN] with your Mintlify subdomain
    • Replace [YOUR_DOMAIN] with your website’s domain
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);
  }
}
  1. Click Deploy and wait for changes to propagate (may take a few hours)

Need help? Contact our support team for assistance with custom subdirectory setup.

Was this page helpful?