HTTP Header and Method-Based Routing
What you'll learn: How to route incoming requests to different backend servers based on HTTP headers, request methods, query parameters, and source IPs.
You already know that Application Load Balancers can route traffic based on hostname (e.g., api.example.com) and path (e.g., /images). But modern applications often need even finer control. That's where HTTP header and method-based routing comes in.
The Core Idea
Think of an ALB rule as a sophisticated mail sorter. Instead of just reading the recipient's name (hostname) or address (path), it can also check:
- HTTP headers – Custom headers like
X-User-Type: premiumor standard ones likeUser-Agent: mobile-app - HTTP methods –
GET,POST,PUT,DELETE, etc. - Query parameters –
?version=2or?region=eu - Source IP addresses – Requests from specific CIDR blocks
This lets you create rules like:
- "Send all
POSTrequests to the write-optimized target group" - "Route requests with header
X-Beta-Tester: trueto the canary environment" - "Direct mobile users (based on
User-Agent) to mobile-optimized backends" - "Block or route traffic differently based on source IP ranges"
Why This Matters
Instead of deploying separate load balancers or relying on application logic alone, you can implement traffic segmentation, A/B testing, API versioning, and security filtering directly at the load balancer layer—before requests ever hit your servers.
Key Takeaway:
HTTP header and method-based routing extends ALB rules beyond simple host/path matching, enabling sophisticated traffic control based on request metadata, methods, query strings, and client IPs—all without changing your application code.