Put your help center on a sub-folder with Cloudflare
Serve your help center at a path on your site, such as yourcompany.com/help, with a Cloudflare Worker in front of your site. Your domain's DNS must be on Cloudflare.
Needs a payment method on file, which a trial with a card meets. Owners and admins can change this.
Set the sub-folder in Ferndesk
In Help Center > Customize > Custom Domain, choose Custom sub-folder, enter your site's domain and a path such as /help, and click Configure subdirectory. Copy the Proxy host we show you (it looks like yourcompany.hc.ferndesk.com). The examples below use /help and www.yourcompany.com; replace them with your own.
Create the Worker
In Cloudflare, create a Worker (from the Hello World template) named something like
ferndesk-proxy, and deploy it.In the Worker's Settings, under Domains & Routes, add two routes on your zone:
*yourcompany.com/help*and*yourcompany.com/_ferndesk*. The second one serves the help center's scripts and styles, so pages load unstyled without it.Edit the Worker's code, replace it with the code below, set
HELP_HOSTto your proxy host andPROXY_PREFIXto your path, and deploy.
const HELP_HOST = 'your-company.hc.ferndesk.com'; // your Ferndesk help domain
const PROXY_PREFIX = '/help'; // the subfolder you chose in Ferndesk
const PROXY_VERSION = '2';
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const originalUrl = new URL(request.url);
// Keep canonical trailing-slash behaviour on the edge
if (originalUrl.pathname.endsWith('/') && originalUrl.pathname !== '/') {
originalUrl.pathname = originalUrl.pathname.slice(0, -1);
return Response.redirect(originalUrl.toString(), 301);
}
// Only intercept the help subtree (and the help assets)
if (
originalUrl.pathname !== PROXY_PREFIX &&
!originalUrl.pathname.startsWith(`${PROXY_PREFIX}/`) &&
!originalUrl.pathname.startsWith('/_ferndesk/')
) {
return fetch(request);
}
// Build the upstream request with the prefix removed
const upstreamUrl = new URL(originalUrl.toString());
upstreamUrl.hostname = HELP_HOST;
if (upstreamUrl.pathname === PROXY_PREFIX) {
upstreamUrl.pathname = '/';
} else if (upstreamUrl.pathname.startsWith(`${PROXY_PREFIX}/`)) {
upstreamUrl.pathname = upstreamUrl.pathname.slice(PROXY_PREFIX.length) || '/';
}
// Enables edge caching: tells Ferndesk this render belongs to your
// subfolder so it gets its own cache entry.
upstreamUrl.searchParams.set('__bp', PROXY_PREFIX);
const proxyRequest = new Request(upstreamUrl.toString(), request);
// Let the help app know we are hosted under the subfolder
proxyRequest.headers.set('X-Ferndesk-Base-Path', PROXY_PREFIX);
proxyRequest.headers.set('X-Forwarded-Host', originalUrl.host);
proxyRequest.headers.set('X-Ferndesk-Original-Host', originalUrl.host);
proxyRequest.headers.set('X-Ferndesk-Proxy-Version', PROXY_VERSION);
// Handle redirects ourselves so renamed articles redirect visitors on
// this domain instead of being followed silently.
const response = await fetch(proxyRequest, { redirect: 'manual' });
if (response.status >= 300 && response.status < 400) {
return rewriteRedirect(response, originalUrl);
}
return response;
}
// Translates an upstream redirect (on the Ferndesk help host) back onto
// this site's host and subfolder. External redirects pass through as-is.
function rewriteRedirect(response, originalUrl) {
const location = response.headers.get('location');
if (!location) return response;
const target = new URL(location, `https://${HELP_HOST}`);
if (target.hostname !== HELP_HOST) return response;
target.protocol = 'https:';
target.host = originalUrl.host;
target.searchParams.delete('__bp');
const alreadyPrefixed =
target.pathname === PROXY_PREFIX || target.pathname.startsWith(`${PROXY_PREFIX}/`);
if (!alreadyPrefixed) {
target.pathname = target.pathname === '/' ? PROXY_PREFIX : PROXY_PREFIX + target.pathname;
}
// Response headers from fetch are immutable; copy to edit Location.
const rewritten = new Response(response.body, response);
rewritten.headers.set('location', target.toString());
return rewritten;
}The Worker removes the path before forwarding, sets the two headers we need, and rewrites redirects (for example from renamed articles) back onto your domain.
Check that it works
Open https://www.yourcompany.com/help. Your help center should load with its styling, and links between articles should stay on your domain. Cloudflare's free plan limits how many Worker requests run each day, so check its limits for a busy help center. If something is off, see Troubleshoot your help center.
For a subdomain instead, or for other hosts, see Connect a custom domain to your help center.