Coloca tu centro de ayuda en una subcarpeta con Cloudflare
Publica tu centro de ayuda en una ruta de tu sitio, como yourcompany.com/help, con un Worker de Cloudflare delante de tu sitio. El DNS de tu dominio debe estar en Cloudflare.
Se requiere un método de pago registrado; basta con una prueba gratuita con tarjeta. Los propietarios y administradores pueden cambiar esta configuración.
Configura la subcarpeta en Ferndesk
En Centro de ayuda > Personalizar > Dominio personalizado, elige Subcarpeta personalizada, introduce el dominio de tu sitio y una ruta como /help, y haz clic en Configurar subdirectorio. Copia el Host del proxy que te mostramos (tiene un formato similar a yourcompany.hc.ferndesk.com). En los ejemplos siguientes se usan /help y www.yourcompany.com; sustitúyelos por los tuyos.
Crea el Worker
En Cloudflare, crea un Worker (a partir de la plantilla Hello World) con un nombre como
ferndesk-proxye impleméntalo.En Configuración del Worker, en Dominios y rutas, añade dos rutas en tu zona:
*yourcompany.com/help*y*yourcompany.com/_ferndesk*. La segunda sirve los scripts y estilos del centro de ayuda; sin ella, las páginas se cargarán sin estilos.Edita el código del Worker, sustitúyelo por el código siguiente, configura
HELP_HOSTcon el host del proxy yPROXY_PREFIXcon tu ruta, e impleméntalo.
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;
}El Worker elimina la ruta antes de reenviar la solicitud, establece los dos encabezados que necesitamos y reescribe las redirecciones (por ejemplo, las de artículos cuyo nombre ha cambiado) para que vuelvan a tu dominio.
Comprueba que funciona
Abre https://www.yourcompany.com/help. Tu centro de ayuda debería cargarse con sus estilos, y los enlaces entre artículos deberían permanecer en tu dominio. El plan gratuito de Cloudflare limita la cantidad de solicitudes a Workers que se ejecutan cada día, así que comprueba esos límites si tienes un centro de ayuda con mucho tráfico. Si algo no funciona, consulta Solucionar problemas del centro de ayuda.
Si prefieres usar un subdominio u otro proveedor de alojamiento, consulta Conectar un dominio personalizado a tu centro de ayuda.