Set up subpath hosting with Cloudflare

Learn how to host your help center on a subpath using a Cloudflare Worker.

4 min read

You can host your Notiondesk help center on a subpath of your main domain using Cloudflare Workers.

For example, instead of using a subdomain like help.yourdomain.com, you can serve your help center from:

yourdomain.com/help

yourdomain.com/docs

yourdomain.com/support

This setup is useful when your main website already uses Cloudflare and you want your documentation or support content to stay under the same domain.


Before you start

Before setting up subpath hosting with Cloudflare, make sure you have:

  • An existing Notiondesk help center
  • A domain managed through Cloudflare
  • A subpath you want to use for your help center, such as:
    • /help
    • /docs
    • /support
  • Subpath hosting enabled in Notiondesk

icon
Note: This setup is recommended when your main website domain already uses Cloudflare. If your website is hosted on another provider, you may want to use one of the other subpath hosting guides instead.

Enable subpath hosting in Notiondesk

First, enable subpath hosting from your Notiondesk dashboard.

  1. Open your Notiondesk dashboard.
  1. Go to Settings > General
  1. Scroll down to the Domains section
  1. Enable the Subpath switch
  1. Select Cloudflare as your setup provider
  1. Copy the Cloudflare Worker code generated by Notiondesk

Notiondesk automatically generates the Cloudflare Worker code with the correct values for your help center.

You should copy the code directly from your own dashboard, because it contains values specific to your setup, such as:

  • Your Notiondesk origin host
  • Your custom domain
  • Your selected subpath

Create a Cloudflare Worker

Next, create a Cloudflare Worker that will proxy your help center subpath to Notiondesk.

  1. Open your Cloudflare dashboard
  1. Go to Workers & Pages
  1. Click Create application
  1. Select Worker
  1. Create a new Worker
  1. Open the Worker editor
  1. Replace the default code with the code generated by Notiondesk
  1. Click Save and deploy

After deploying the Worker, Cloudflare will make it available, but it will not yet run on your help center URL. You need to configure a route so Cloudflare knows when to trigger the Worker.

Configure the Cloudflare route

After deploying the Worker, you need to tell Cloudflare when this Worker should run. The Worker should only run on your selected help center subpath.

For example, if your help center should be available at yourdomain.com/help , add a Worker route like this yourdomain.com/help*

This makes Cloudflare run the Worker for:

  • yourdomain.com/help
  • yourdomain.com/help/collections/getting-started
  • yourdomain.com/help/articles/example-article
  • yourdomain.com/help/contact

You also need to make sure the Notiondesk internal route is handled: yourdomain.com/_nd/*

Add the route in Cloudflare

  1. Open your Worker in the Cloudflare dashboard
  1. Go to Settings
  1. Open Domains & Routes
  1. Click Add route
  1. Select your zone
  1. Add your help center route, example: yourdomain.com/help*
  1. Add the internal Notiondesk route, example: yourdomain.com/_nd/*
  1. Save your changes

icon
Use the subpath you selected in Notiondesk. If you chose /docs, your route should be yourdomain.com/docs*.

If you chose /support, your route should be yourdomain.com/support*.

Cloudflare’s official documentation also explains how Worker routes and custom domains for Workers work if you need more details.

Cloudflare Worker example

const ORIGIN_HOST = "your-help-center.notiondesk.help";
const CUSTOM_HOST = "yourdomain.com";
const SUBPATH = "/help";

function isSubpathRequest(pathname) {
  return pathname === SUBPATH || pathname.startsWith(SUBPATH + "/");
}

export default {
  async fetch(request) {
    const url = new URL(request.url);
    const shouldProxy =
      isSubpathRequest(url.pathname) || url.pathname.startsWith("/_nd/");

    if (!shouldProxy) {
      return fetch(request);
    }

    url.hostname = ORIGIN_HOST;

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

    if (isSubpathRequest(url.pathname)) {
      proxyRequest.headers.set("X-Site-Path-Prefix", SUBPATH);
    }

    return fetch(proxyRequest);
  },
};
icon
This is only an example. Use the Worker code generated in your Notiondesk dashboard for your own help center.

Verify your setup

After the Worker is deployed and the routes are configured, open your help center from the subpath you selected. Check that the main help center page loads correctly.

What to check

Make sure that:

  • The help center loads under your main domain
  • Article pages open correctly
  • Images, scripts, and styles load correctly
  • The browser URL stays on your custom domain

icon
Cloudflare changes can take a few minutes to apply. If the help center does not load immediately, wait a moment and refresh the page.

Related articles

Was this page helpful?