Run an EmDash blog at /blog on your Google Sites™ domain with Cloudflare Workers Routes
Four Workers Routes, one Worker that removes /blog on the way in and adds it back on the way out, one canonical host, a merged sitemap and one robots rule. Measured on www.eryc.my.id.
>_ INSIDE_THE_PAGE
Field | Detail |
|---|---|
Problem | The blog from part 0 lives on its own host; you want it at |
Difficulty | 4 of 5 |
Moving parts | 4 Workers Routes, 1 blog Worker entry file, 1 redirect rule, sitemap merge, 1 robots line |
Reversible | Yes: delete the 4 routes and the blog is back on its own host only |
Time and cost | About 1 hour; Cloudflare free plan |
Skills | Part 0 done, editing a TypeScript file, |
Last verified | 2026-11-22 on www.eryc.my.id |
Is it possible?
Yes. Google Sites keeps every path it has; Cloudflare sends only /blog and EmDash's two system folders to the blog Worker. EmDash never learns it lives under /blog: the Worker removes the prefix on the way in and puts it back into every link on the way out. I rate it 4 of 5 because it sits in front of real traffic, and a mistake shows up on the whole domain, not just the blog.
This is part 2 of the series EmDash for Google Sites. It needs part 0 (blog created, Worker in front of the Site).
What is the big picture?
The blog lives at /blog without EmDash knowing: the Worker removes the prefix on the way in and adds it back on the way out.
The same flow as text:
- A request comes in:
GET www.example.com/blog/posts/hello/. - Workers Routes:
www.example.com/blog/*is more specific thanwww.example.com/*, so it wins. - The blog Worker maps the host to
blog.example.comand the path to/posts/hello/. - EmDash renders the page as if it lived at the root.
- On the way out, the blog Worker rewrites
href,src,action,posterandsrcset:/posts/xbecomes/blog/posts/x. - It also rewrites the
Locationheader, sitemap and RSS text, and JSON-LD script text, from the blog host towww.example.com/blog/.... - The browser sees only
www.example.com/blog/....
Where it fits with part 0: same two Workers, same bindings. This part adds routes on the main host and a wrapper around EmDash's own Worker entry. Nothing changes in D1, R2 or the Google Sites Worker.
Which words do I need?
Word | Meaning here |
|---|---|
Workers Route | A URL pattern on your zone that sends matching requests to one Worker |
More specific wins | When two routes match, Cloudflare uses the more specific one, so |
Prefix stripping | Removing |
HTMLRewriter | Cloudflare's streaming HTML editor; it changes attributes and text as the page passes through |
| Where a redirect points; it must be rewritten too, or a redirect leaks the blog host |
Canonical host | The one address search engines should index; the other one 301s to it |
Service binding | A direct Worker-to-Worker call with no public request; the main Worker uses one to read the blog's sitemap |
JSON-LD | Structured data in a |
Step 1: Add the routes
Where it fits: the ROUTE box.
Four patterns go to the blog Worker. /_emdash/* carries the admin and the API, /_astro/* the CSS and JavaScript.
"routes": [ { "pattern": "www.example.com/blog", "zone_name": "example.com" }, { "pattern": "www.example.com/blog/*", "zone_name": "example.com" }, { "pattern": "www.example.com/_emdash/*", "zone_name": "example.com" }, { "pattern": "www.example.com/_astro/*", "zone_name": "example.com" }, { "pattern": "blog.example.com", "custom_domain": true }]Merge these into the wrangler.jsonc that part 0 created. Keep its name and bindings as generated.
Check. Cloudflare dashboard > your domain > Workers Routes lists the four patterns with your blog Worker, and www.example.com/* with the Sites Worker.

OBSERVED My zone's Workers Routes: the main Worker takes www.eryc.my.id/*, the blog Worker takes /blog, /blog/*, /_emdash/* and /_astro/*. Captured 2026-11-22.
OBSERVED My zone has 11 routes: the four above for the blog, the main-site routes, and a few for other small Workers. The four blog routes beat www.eryc.my.id/* because they are more specific.
Step 2: Strip the prefix on the way in
Where it fits: the STRIP /blog box.
EmDash's Worker entry is wrapped, not edited. The wrapper changes the request, then calls EmDash's own handler:
const BLOG_HOST = "blog.example.com";const PUBLIC_HOST = "www.example.com";const PREFIX = "/blog"; const url = new URL(request.url);const target = new URL(request.url);target.hostname = BLOG_HOST;if (url.pathname === PREFIX || url.pathname.startsWith(PREFIX + "/")) { target.pathname = url.pathname.slice(PREFIX.length) || "/";}const res = await handler.fetch(new Request(target.toString(), request), env, ctx);/_emdash/... and /_astro/... keep their path; only the host changes.
Try any path:
Step 3: Put the prefix back on the way out
Where it fits: the HTMLREWRITER box.
const fixPath = (v) => v && v.startsWith("/") && !v.startsWith("//") && !v.startsWith(PREFIX + "/") && !v.startsWith("/_emdash") ? PREFIX + v : v; new HTMLRewriter() .on("[href]", attr("href", fix)) .on("[src]", attr("src", fix)) .on("[action]", attr("action", fix)) .on("[poster]", attr("poster", fix)) .on("[srcset]", attr("srcset", fixSrcset)) .on("meta[content^='https://" + BLOG_HOST + "']", attr("content", fix)) .on('script[type="application/ld+json"]', jsonLd());Redirects get the same treatment through the Location header, and XML (sitemap, RSS) gets a plain text replace of the blog host.
Check. MEASURED On 2026-11-22, www.eryc.my.id/blog/ returned 200 in 465 ms (one request from my browser in Malang). It had 19 internal href, src and action values, 0 without the /blog or /_emdash prefix. The RSS feed had 0 mentions of the blog host and 4 links under www.eryc.my.id/blog/. /blog without the slash also returned 200.
Step 4: One canonical host
Where it fits: the blog host, outside the main flow.
Readers who land on the blog's own host get a 301 to the /blog address. The admin and assets stay, because the admin sign-in belongs to that host:
if ( u.hostname === BLOG_HOST && (request.method === "GET" || request.method === "HEAD") && !u.pathname.startsWith("/_emdash") && !u.pathname.startsWith("/_astro")) { return Response.redirect("https://" + PUBLIC_HOST + PREFIX + u.pathname + u.search, 301);}Check. MEASURED On 2026-11-22, blog.eryc.my.id/posts/<slug>?x=1 ended on www.eryc.my.id/blog/posts/<slug>?x=1, with the query string kept. blog.eryc.my.id/_emdash/admin stayed on the blog host and showed the EmDash admin.
Step 5: Sitemap and robots
Where it fits: the main Worker, which owns /sitemap.xml and /robots.txt for the whole domain.
The main Worker reads the blog's sitemap through a service binding to the blog Worker, keeps only URLs under www.example.com/blog/, and adds them to the site's sitemap. It does this on every request, so a published post appears and a deleted one disappears with no manual step. If the blog Worker does not answer, the sitemap is served without blog URLs instead of failing. robots.txt gets one line in every group that is allowed to crawl:
Disallow: /_emdash/Check. MEASURED On 2026-11-22 my sitemap was one urlset with 8 URLs, including /blog/ and one published test post. After I deleted that test post it had 6 URLs and no blog URL: the /blog/ hub is only listed while at least one post exists. robots.txt had 36 User-agent lines: 21 groups allowed to crawl, each with Disallow: /_emdash/, and 15 blocked scrapers with Disallow: /.
NOT TESTED The sitemap merge is part of my production Worker and is not in the repo yet; the repo covers Steps 1 to 4.
What went wrong?
- The structured data leaked the blog host. While measuring this post, the blog home still had
https://blog.eryc.my.idtwice, as the@idandurlof itsWebSiteJSON-LD. Attribute handlers never see<script>text. The fix buffers the script text and rewrites it (jsonLd()above). MEASURED In a local test with a 20 KB JSON-LD block split across chunks,0blog-host URLs were left and the JSON still parsed. NOT TESTED On the live site, because my browser was being blocked by the site's own protection at the time of writing. - Three routes were not enough. An earlier note said three routes; the dashboard shows four, because
www.example.com/blog(no slash) is its own pattern. - A build failed once for no code reason. Workers Builds deploys a push to
mainin about 100 to 150 seconds; one build failed and an empty commit rebuilt it.
Limits
- Links built in JavaScript or written in inline CSS are not rewritten.
- NOT TESTED Heavy traffic, and updating EmDash with this wrapper in place.
- While EmDash's
stagingflag is on, pages arenoindex. Turn it off before you expect indexing. - Everything depends on route specificity. A broader route added later can take over
/blog.
Files and reproduction
Repo: ErycTheGreat/emdash-for-google-sites, folder 02-blog-on-sites-domain: worker.ts (the whole wrapper, example.com only), wrangler.example.jsonc (the routes to merge) and CHECK.md (seven curl checks with the expected result for each). With an AI agent: "Use the emdash-for-google-sites skill, part 02"; it asks before it adds any route to a live zone.
Series: part 0, setup · part 2, this post · part 1, the redirect fix · part 3, matching the look.
How this was made
Built and run by Eryc Tri Juni S on his own site. Measurements come from his browser and from a local Miniflare test on 2026-11-22; the routes capture is from his Cloudflare dashboard, account name blurred. Drafted with AI assistance (Claude); every sentence was reviewed and every fact checked by the author.
About the author
Eryc Tri Juni S is an Edge SEO & GEO (Generative Engine Optimization) Specialist in Malang, Indonesia, an Electrical Engineer with 8 years in electronic product innovation, now at the intersection of Edge SEO, GEO, and AI retrieval infrastructure. About · GitHub
Changelog
- 2026-11-22: first version.
Google Sites is a trademark of Google LLC. This project is not affiliated with or endorsed by Google.
Related prompts
- 01
How do I put a blog in a subfolder of a Google Sites domain?
- 02
Subfolder or subdomain for a blog: which is better for SEO?
- 03
How do Cloudflare Workers Routes decide which Worker runs?