One HTTPS domain routes /api and its slash descendants to an API target group, and /images and its slash descendants to an image target group. Exclude names such as /apiv2; return fixed 404 for everything else. Certificates, SGs, health checks, and healthy targets are prepared.
Applications accept the original paths. No URL rewrite transform or competing rule is configured. Match paths case-sensitively and do not use query strings for routing.
Which listener rules meet the requirements?
Forward explicit base and slash-descendant path patterns to separate target groups and handle the remainder with the default.
Detailed explanation
The slash in /api/* is required, so /api itself does not match. Add each exact base path because it is explicitly required.
ALB evaluates smaller priority numbers first and applies the first matching rule. The earlier /* also matches API requests, preventing selection of the API rule.
These broad prefixes include unintended names. Match the exact base plus /* to limit descendants to the required slash boundary.
The two values in each path-pattern condition are alternatives. Include the exact base and slash descendants; the last default handles requests matching neither rule.
Check official documentation
Compare the following points with the official documentation.
On an approved test ALB, inspect priorities, path-pattern values, forward targets, and default. Request /api, /api/, /api/items, /images, /images/a.png, /apiv2, /other, and /API and compare responses with target logs. Also test /api/items?v=1 and record the original path.
Official references
What to confirm
API base and descendants reach API; image base and descendants reach images. /apiv2, /other, and /API return fixed 404. Query changes alone do not change routing; without rewrite, targets receive the original path.
Key points
- path-pattern
- Rule priority
- Default action
Notes
- Environment: Official ALB documentation and an approved HTTPS test ALB with observable applications
- Reviewed against the linked AWS documentation on 2026-10-15.
Foundation review
Specify the base separately from descendants
Values /api and /api/* in one path-pattern condition match either alternative. /api/* alone excludes /api; /api* also includes /apiv2. Apply the same boundary to images.
Check order and default handling
ALB evaluates smaller priority numbers first and applies the matching rule. Use 10 and 20 for these nonoverlapping paths and fixed 404 as the last default. An earlier broad /* can shadow specific rules.
Separate routing from rewriting
Path matching is case-sensitive and excludes query parameters. A path-pattern condition does not itself rewrite a URL. With no rewrite transform here, /api/items reaches the target unchanged, so the application must handle that path.