HeadlinesBriefing favicon HeadlinesBriefing.com

Hosting Blogs on Subdirectories: A Cloudflare Workers Guide

Hacker News •
×

Hosting blogs on subdirectories (e.g., example.com/blog) instead of subdomains improves SEO by consolidating domain authority, per SEO best practices. While subdomains are often treated as separate entities by search engines, empirical data shows subdirectories yield 40% better rankings, as noted in ButterCMS research. This method also enhances user experience through unified branding and navigation.

The process requires technical precision: DNS records must be configured to proxy traffic through Cloudflare, with careful attention to avoid wildcard entries. For developers using Next.js, setting the basePath to "/blog" in next.config.js ensures static assets route correctly. A Cloudflare Worker then redirects subdirectory requests to the original subdomain, handling HTTP methods and URL rewriting. This setup demands meticulous configuration but avoids third-party CMS complexities.

A critical step involves managing search engine indexing. By updating the robots.txt file in the Next.js app, publishers prevent duplicate content penalties from indexing both subdomain and subdirectory versions. This technical adjustment maintains SEO integrity post-migration.

The guide emphasizes practical application over theory, offering actionable steps for developers. While setup complexity deters some, the combination of Vercel for hosting, Render for static sites, and Cloudflare Workers creates a scalable solution. Successful implementation results in a streamlined blog infrastructure with measurable SEO benefits.