Docs

Docs

Features

Hosting /blog with Cloudflare

August 12, 2025

This feature is available in the Startup plan ($39/mo plan).

This feature is only enabled for blog and docs websites for the following subdirectories

  • /blog

Enable subdirectory host in dashboard /blog

Enable the proxy option in Cloudflare DNS (the orange icon)

To host on a subdirectory you will need to create a Cloudflare worker to rewrite traffic from a subdirectory to BlogPro websites. To do this you need to have the orange icon (the proxy option) enabled for your domain.

Copy the code to paste in Cloudflare workers

Adjust BLOGPRO_SUBDOMAIN with your subdomain name in blogpro dashboard.

// worker.js
const BLOGPRO_SUBDOMAIN = "blogpro-blog"; // Change this to your blogpro-blog

const TARGET_ORIGIN = `https://${BLOGPRO_SUBDOMAIN}.blogpro.so`;
const TARGET_PATHNAME = "blog";

export default {
  async fetch(request) {
    const incoming = new URL(request.url);

    const mount = ensureLeadingSlash(TARGET_PATHNAME .replace(/\/+$/, ""));
    const stripRe = new RegExp(`^${escapeRegExp(mount)}(?:/)?`);

    const shouldRewrite =
      incoming.pathname === mount || incoming.pathname.startsWith(mount + "/");

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

    let newPath = incoming.pathname.replace(stripRe, "/");
    if (newPath === "") newPath = "/";

    const target = new URL(TARGET_ORIGIN);
    target.pathname = newPath;
    target.search = incoming.search;

    const upstreamReq = new Request(target.toString(), request);
    const res = await fetch(upstreamReq);

    return new Response(res.body, { status: res.status, headers: res.headers });
  },
};

function escapeRegExp(s) {
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function ensureLeadingSlash(s) {
  return s.startsWith("/") ? s : "/" + s;
}
javascript

Create the Cloudflare worker

  1. Go to cloudflare.com and log in
  1. Go to the Compute (Workers) tab
  1. Click create service and choose Start with Hello World! template.
  1. Name your service with something like BlogPro {websiteName} and create it
  1. Click the Edit Code button and paste the BlogPro code

Create worker routes

  1. Add route on worker routes at selected domain.
  1. Fill the route with your domain with blog as subdirectory like below, don’t forget to add asterisk at the end of the string (*). (yourdomain.com/blog*)
  1. Then choose the worker created before
  1. Save and try out your new website in a subdirectory!

FAQ

How much time does it take for the changes to take effect?
Can i host any website in a subdirectory this way?
Do i need Cloudflare or does this work with any other DNS provider?
Why is the orange icon (proxy option) required?