Redirect direct visits to ai-inequality-theta.vercel.app to policyengine.org

Open Beginner friendly
#48 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
json, next.js

Research direction

Start by reading vercel.json and the existing deployment configuration, then add the host-conditional redirect rules described in the issue, including the UK route rules before the general rules. Check that the JSON is valid and that the rules preserve policyengine.org proxy requests; after deployment, run the two curl checks in the issue to confirm the direct host redirects and the policyengine.org page still returns 200.

Written by the indexing model from the issue text.

Description

policyengine.org serves this app at https://www.policyengine.org/us/ai-inequality: policyengine-app-v2's website/src/data/appZoneRoutes.ts proxies that path to https://ai-inequality-theta.vercel.app. The host also serves every page itself, outside the site, so links to it keep turning up in posts, emails and READMEs. A visit straight to ai-inequality-theta.vercel.app should land on the same page on policyengine.org.

The change

This app builds as a static export in production (output: "export" in next.config.mjs), and Next documents redirects() as unsupported there. Vercel applies vercel.json redirects to a static export built with its Next.js preset (tested on a Next 16.2 export, 2026-10-29). Add these redirects to vercel.json.

{
  "redirects": [
    {
      "source": "/",
      "has": [
        {
          "type": "header",
          "key": "x-forwarded-host",
          "value": "ai-inequality-theta\\.vercel\\.app"
        }
      ],
      "destination": "https://www.policyengine.org/us/ai-inequality",
      "permanent": true
    },
    {
      "source": "/(.*)",
      "has": [
        {
          "type": "header",
          "key": "x-forwarded-host",
          "value": "ai-inequality-theta\\.vercel\\.app"
        }
      ],
      "destination": "https://www.policyengine.org/$1",
      "permanent": true
    }
  ]
}

Vercel sets x-forwarded-host to the host the visitor asked for, and overwrites any value the visitor sends. That's ai-inequality-theta.vercel.app on a direct visit and www.policyengine.org on a request policyengine.org proxies. So these rules leave policyengine.org's own requests alone, and preview deployments too, since a preview has a host of its own. The pattern, how it was tested and its pitfalls: policyengine-app-v2 docs, "The direct-host redirect". PolicyEngine/ballot-measures-2026#8 adopts it with tests.

The UK route

policyengine.org also serves this app at /uk/ai-inequality, and proxies it to this host's /us/ai-inequality?country=uk. With only the rules above, a direct link with ?country=uk lands on https://www.policyengine.org/us/ai-inequality?country=uk: the UK view at a US address. To send it to /uk/ai-inequality, put these two rules first, ahead of the two above:

[
  {
    "source": "/us/ai-inequality",
    "has": [
      {
        "type": "header",
        "key": "x-forwarded-host",
        "value": "ai-inequality-theta\\.vercel\\.app"
      },
      {
        "type": "query",
        "key": "country",
        "value": "uk"
      }
    ],
    "destination": "https://www.policyengine.org/uk/ai-inequality",
    "permanent": true
  },
  {
    "source": "/us/ai-inequality/(.*)",
    "has": [
      {
        "type": "header",
        "key": "x-forwarded-host",
        "value": "ai-inequality-theta\\.vercel\\.app"
      },
      {
        "type": "query",
        "key": "country",
        "value": "uk"
      }
    ],
    "destination": "https://www.policyengine.org/uk/ai-inequality/$1",
    "permanent": true
  }
]

The query rides along, so the reader lands on https://www.policyengine.org/uk/ai-inequality?country=uk, which serves the same page.

Canonical link and og:url

Once the host redirects, a page whose <link rel="canonical"> or og:url names ai-inequality-theta.vercel.app names a URL that redirects back to it, and policyengine-app-v2's audit fails a redirecting zone whose page does. This page sets neither today (checked 2026-10-29); if you add them, use its https://policyengine.org URL.

Assets and API calls

These rules also redirect direct requests for the host's own assets and API routes. Pages served through policyengine.org load theirs through policyengine.org, so readers there never meet the redirect. But a browser blocks a cross-origin call whose redirect carries no CORS headers, so check that no code calls this host by absolute URL. A code search of the default branch for ai-inequality-theta.vercel.app found nothing (2026-10-29).

Check it

/us/ai-inequality already serves this app on policyengine.org, so this can ship whenever it suits you. After the production deploy:

curl -sI "https://ai-inequality-theta.vercel.app/us/ai-inequality"

That should answer 308 with location: https://www.policyengine.org/us/ai-inequality, and curl -sI "https://www.policyengine.org/us/ai-inequality" should still answer 200.

Then, in policyengine-app-v2, run node .github/scripts/audit-zone-direct-hosts.mjs, and add "/us/ai-inequality" to DIRECT_HOST_REDIRECTS there so the daily audit keeps the redirect in place.

🤖 Generated with Claude Code

Dominant language
Python
Stars
1
Forks
1
Avg merge
2d 21h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PolicyEngine/ai-inequality

All issues in PolicyEngine/ai-inequality

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.