The State of Docs Report 2025 is live! Dive in and see why docs matter more than ever:
Read the report
LogoLogo
ProductPricingLog inSign up
  • Documentation
  • Developers
  • Guides
  • Changelog
  • Help Center
  • Getting Started
    • GitBook Documentation
    • Quickstart
    • Importing content
    • GitHub & GitLab Sync
      • Enabling GitHub Sync
      • Enabling GitLab Sync
      • Content configuration
      • GitHub pull request preview
      • Commit messages & Autolink
      • Monorepos
      • Troubleshooting
  • Creating Content
    • Formatting your content
      • Inline content
      • Markdown
    • Content structure
      • Spaces
      • Pages
      • Collections
    • Blocks
      • Paragraphs
      • Headings
      • Unordered lists
      • Ordered lists
      • Task lists
      • Hints
      • Quotes
      • Code blocks
      • Files
      • Images
      • Embedded URLs
      • Tables
      • Cards
      • Tabs
      • Expandable
      • Stepper
      • Drawings
      • Math & TeX
      • Page links
    • Reusable content
    • Broken links
    • Searching content
      • Search & Quick find
      • GitBook AI
    • Writing with GitBook AI
    • Version control
  • API References
    • OpenAPI
      • Add an OpenAPI specification
      • Insert API reference in your docs
    • Guides
      • Structuring your API reference
      • Adding custom code samples
      • Managing API operations
      • Describing enums
      • Integrating with CI/CD
  • Extensions reference
  • Publishing Documentation
    • Publish a docs site
      • Public publishing
      • Private publishing with share links
    • Site structure
      • Content variants
      • Site sections
    • Site customization
      • Icons, colors, and themes
      • Layout and structure
      • Extra configuration
    • Set a custom domain
    • Setting a custom subdirectory
      • Configuring a subdirectory with Cloudflare
      • Configuring a subdirectory with Vercel
    • Site settings
    • Site insights
    • Site redirects
    • Visitor authentication
      • Enabling visitor authentication
      • Setting up Auth0
      • Setting up Azure AD
      • Setting up AWS Cognito
      • Setting up Okta
      • Setting up OIDC
      • Setting up a custom backend
  • LLM-ready docs
  • Collaboration
    • Live edits
    • Change requests
    • PDF export
    • Inviting your team
    • Comments
    • Notifications
  • Integrations
    • Install and manage integrations
    • GitHub Copilot
  • Account management
    • Plans
      • Legacy pricing
      • Sponsored site plan
      • Non-profit plan
      • Billing policy
    • Subscription cancellations
    • Personal settings
    • Organization settings
    • Member management
      • Invite or remove members
      • Roles
      • Teams
      • Permissions and inheritance
    • SSO & SAML
      • SSO Members vs non-SSO
  • Resources
    • GitBook UI
    • Keyboard shortcuts
    • Glossary
Powered by GitBook
LogoLogo

Resources

  • Showcase
  • Enterprise
  • Status

Company

  • Careers
  • Blog
  • Community

Policies

  • Subprocessors
  • Terms of Service
On this page

Was this helpful?

Edit on GitHub
  1. Publishing Documentation
  2. Setting a custom subdirectory

Configuring a subdirectory with Cloudflare

Host your documentation with a /docs subdirectory using Cloudflare

Last updated 1 month ago

Was this helpful?

1

Configuring your GitBook site

In your GitBook organization, click on your docs site name in the sidebar, then click Manage site or open the Settings tab. Open the Domain and redirects section and under ‘Subdirectory’, click Set up a subdirectory.

Enter the URL where you would like to host your docs. Then specify the subdirectory for docs access, e.g. tomatopy.pizza/docs, and click Configure.

Under Additional configuration, you will now see a proxy URL. You'll use this in the next step when configuring your Cloudflare worker. Copy it to your clipboard.

2

Create your Cloudflare worker

Sign into your Cloudflare account and navigate to Workers & Pages

Click the Create button.

On the ‘Create an application’ screen, click the Hello world button in the ‘Start from a template’ card.

Give the worker a more descriptive name, like mydocs-subpath-proxy. Once you finish renaming the worker, click Deploy.

3

Configure your custom domain

Your worker will get a default URL that you can use. To configure your custom domain instead (such as tomatopy.pizza), click Settings. Then, in the ‘Domains & Routes’ section, click + Add.

In the ‘Domains & Routes’ tray that opens, click Custom domain, then enter your custom domain in the textbox that follows. When you specify the custom domain, do not include the subdirectory. For example, tomatopy.pizza is correct, while tomatopy.pizza/docs is not.

4

Update the worker code

When the worker is finished deploying, click Edit code, or click Continue to project, and then the Edit code button in the upper right.

In the code editor that opens, replace the sample code with the following snippet:

export default {
  fetch(request) { 
    const SUBDIRECTORY = '/docs';
    const url = new URL(request.url);
    const proxy = "<INSERT YOUR PROXY URL FROM GITBOOK>" + url.pathname.slice(SUBDIRECTORY.length);
    const proxyURL = new URL(
      proxy.endsWith('/') ? proxy.slice(0, -1) : proxy 
    )
    proxyURL.search = url.search;
    return fetch(new Request(proxyURL, request));
  }
};

Be sure to update the URL on line 5 with the proxy URL you got from GitBook in the first step.

Once that’s done, click Deploy. This process may take a few moments. Once it’s complete, when visiting the URL, you should see your docs site!

This feature is available on the .

Ultimate site plan