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;
}
Create the Cloudflare worker
- Go to cloudflare.com and log in
- Go to the Compute (Workers) tab
- Click create service and choose Start with Hello World! template.
- Name your service with something like
BlogPro {websiteName}
and create it
- Click the
Edit Code
button and paste the BlogPro code
Create worker routes
- Add route on worker routes at selected domain.
- 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*)
- Then choose the worker created before
- 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?