Prompt
How do I execute redirects and auth checks at the network edge?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
To do redirects and auth checks at the network edge, you typically put that logic in a CDN / edge function / reverse proxy layer so requests are handled before they reach your origin app.
Common ways to do it
1. CDN / Edge Functions
Use a provider’s edge runtime to inspect the request and either:
- return a redirect immediately
- allow the request through
- reject it with 401/403
- attach headers or tokens
Examples:
- Cloudflare Workers
- Vercel Edge Middleware
- Netlify Edge Functions
- AWS CloudFront Functions / Lambda@Edge
- Fastly Compute
- Akamai EdgeWorkers
2. Reverse Proxy Rules
If you control the proxy layer, you can do this with:
- Nginx
- Envoy
- Traefik
- Apache
- API gateways like Kong, Apigee, AWS API Gateway
These can enforce:
- path-based redirects
- host-based redirects
- JWT validation
- header checks
- IP allow/deny rules
Typical flow
- Request arrives at the edge
- Edge code checks:
- path
- host
- cookies
- auth headers
- JWT/session token
- geo/IP/device rules
- Edge returns:
301/302/307/308redirect, or401/403unauthorized/forbidden, or- forwards to origin
Example: redirect at the edge
Pseudo-code:
if (request.url.pathname === "/old-page") {
return Response.redirect("https://example.com/new-page", 301);
}
Example: auth check at the edge
Pseudo-code:
const token = request.headers.get("Authorization");
if (!token || !isValid(token)) {
return new Response("Unauthorized", { status: 401 });
}
Important considerations
- Keep checks fast: edge code should be lightweight.
- Avoid calling origin unless necessary.
- Use signed cookies/JWTs instead of session DB lookups when possible.
- Cache redirect decisions where safe.
- Be careful with secrets: store them in edge secrets/vars, not hardcoded.
- Preserve HTTP semantics:
- use
301/308for permanent redirects - use
302/307for temporary redirects
- use
- Watch for open redirects: validate redirect destinations.
If you want a practical setup
Tell me which platform you’re using, for example:
- Cloudflare
- Vercel
- AWS CloudFront
- Nginx
- Next.js
- Fastly
and I can give you a concrete implementation.