From 200faafcd167ab4c5b41d1901e7396f333edc1f8 Mon Sep 17 00:00:00 2001 From: PavelMakarchuk Date: Fri, 13 Mar 2026 13:00:25 +0100 Subject: [PATCH 1/2] Fix SEO: www base URL + skip middleware for rewritten tool paths - Change BASE_URL from policyengine.org to www.policyengine.org (non-www 307-redirects to www, so all canonical URLs and OG tags generated by middleware pointed to a redirecting URL) - Skip middleware interception for paths that Vercel rewrites to external apps (KYPA, WATCA, TAXSIM, API docs). These apps have their own SSR with full content, meta tags, OG images, and JSON-LD. The middleware was replacing rich SSR pages with 3-line stubs, preventing Google from seeing the actual content. Co-Authored-By: Claude Opus 4.6 --- middleware.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/middleware.ts b/middleware.ts index 4b5575b3e..30ddfc6b4 100644 --- a/middleware.ts +++ b/middleware.ts @@ -24,7 +24,16 @@ type OgMetadata = { }; // Constants -const BASE_URL = "https://policyengine.org"; +const BASE_URL = "https://www.policyengine.org"; + +// Paths that Vercel rewrites to external apps with their own SSR + meta tags. +// Let all user agents (including bots) pass through to the actual app. +const REWRITE_PREFIXES = [ + "/us/keep-your-pay-act", + "/us/watca", + "/us/taxsim", + "/us/api", +]; export const CRAWLER_USER_AGENTS = [ "facebookexternalhit", @@ -414,6 +423,13 @@ export default async function middleware(request: Request) { return; } + // Let rewritten tool paths pass through — the external apps have their own + // SSR, meta tags, OG images, and JSON-LD, so the middleware stub would be + // strictly less content than what the actual app serves. + if (REWRITE_PREFIXES.some((p) => url.pathname.startsWith(p))) { + return; + } + // Let static files (sitemap, robots, etc.) pass through to Vercel's file serving if (url.pathname === "/sitemap.xml" || url.pathname === "/robots.txt") { return; From 49d879ac59f389cd585c960cf648f389b1be5b59 Mon Sep 17 00:00:00 2001 From: PavelMakarchuk Date: Fri, 13 Mar 2026 13:09:19 +0100 Subject: [PATCH 2/2] Remove WATCA from bypass list, fix hardcoded non-www image URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WATCA lacks its own OG tags — bypassing middleware would break social share previews. Also fixes DEFAULT_OG.image to use www. Co-Authored-By: Claude Opus 4.6 --- middleware.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/middleware.ts b/middleware.ts index 30ddfc6b4..ec4e99617 100644 --- a/middleware.ts +++ b/middleware.ts @@ -30,7 +30,6 @@ const BASE_URL = "https://www.policyengine.org"; // Let all user agents (including bots) pass through to the actual app. const REWRITE_PREFIXES = [ "/us/keep-your-pay-act", - "/us/watca", "/us/taxsim", "/us/api", ]; @@ -96,7 +95,7 @@ const DEFAULT_OG = { title: "PolicyEngine", description: "Free, open-source tools to understand tax and benefit policies. Calculate your taxes and benefits, or analyze policy reforms.", - image: "https://policyengine.org/assets/logos/policyengine/teal.png", + image: "https://www.policyengine.org/assets/logos/policyengine/teal.png", }; const STATIC_PAGES: Record = {