Architecture January 28, 2026

The Routing Paradox: Debugging Static Site Architectures

By Kahraman Bayraktar
Editorial NoteThis article was drafted with AI assistance from real engineering problems, debugging sessions, and architectural questions that surfaced during my own software development work. While the underlying experience is real, AI-generated explanations may contain inaccuracies.

What started as a mundane task—"serve a few static HTML files locally"—turned into a crisp lesson on HTTP directory resolution, URL canonicalization, and why clean folder architecture beats server configuration hacks.

In this post, I’ll dissect a classic Redirect Loop we hit during the initial static-HTML iteration of this portfolio (prior to migrating to Next.js App Router), and how fixing the directory layout solved it in 30 seconds.

The Setup

In our early static-HTML layout, the project root looked like this:

  • index.html (Home page)
  • blog.html (Blog listing page)
  • blog/ (A directory at the exact same root level holding posts.json and .md files)

The Problem: Trailing-Slash Directory Redirects vs. Clean URLs

We initially previewed the site locally with Vercel's serve, which enables cleanUrls by default (resolving /blog to blog.html and redirecting /blog.html → /blog).

However, a physical /blog directory also existed at the exact same path stem.

How Web Servers Actually Collide Here

When a browser requests /blog without a trailing slash, standard HTTP static servers and reverse proxies follow two competing rules:

  1. Clean-URL Extension Stripping: Sees /blog.html and issues a 301 redirect to /blog.
  2. Physical Directory Canonicalization: Standard web servers (including Nginx) check the filesystem, see that /blog is an existing directory, and automatically issue a 301 Moved Permanently trailing-slash redirect to /blog/, then look for /blog/index.html.

Because /blog/ only contained posts.json (and no index.html), Nginx returned 403 Forbidden or 404 Not Found on /blog/, while local clean-URL rules and manual .html links bounced between /blog.html, /blog, and /blog/.

Attempt 1: Configuration Patchwork

Our first instinct was to override the server via serve.json—disabling cleanUrls, disabling directory listings, and hardcoding path rewrites:

{
  "cleanUrls": false,
  "rewrites": [
    { "source": "/blog", "destination": "/blog.html" }
  ],
  "directoryListing": false
}

Why it was the wrong fix: Patching local serve.json didn't fix Nginx's try_files $uri $uri/ $uri.html resolution order in production. Every server environment had to be specially configured to work around a self-inflicted naming collision.

Attempt 2: Switching Local Server to http-server

Switching to npx http-server . -c-1 eliminated automatic .html stripping locally, which stopped the redirect loop when requesting /blog.html explicitly—but requesting /blog still hit the /blog/ directory collision.

The Real Solution: Eliminate the Namespace Collision

The root cause wasn't serve or Nginx; it was mixing route entrypoints and raw data directories in the same URL namespace. Naming a data folder /blog/ alongside /blog.html guaranteed path ambiguity on any filesystem-backed HTTP server.

Moving the data assets out of the page route namespace solved the issue across every server immediately:

Before (Colliding Route & Directory Stem)

/root
  ├── blog.html      <-- Page route (/blog or /blog.html)
  └── blog/          <-- Colliding physical directory (/blog/)
      └── posts.json

After (Clean Separation of Routes & Assets)

/root
  ├── blog.html
  └── assets/
      └── data/
          └── blog/
              └── posts.json

Conclusion

We spent far too long tweaking rewrite rules for a problem that took 30 seconds of moving a folder to eliminate permanently.

The Lesson: Whenever you find yourself writing brittle server rewrite rules for a basic static layout, check your filesystem hierarchy first. Separate route entrypoints from static data directories so URL stems never collide.