I have a complicated scenario where I need to redirect domain requests to another domain for some requests but stay in the original domain for others.
For example, if I had www.abc.com:
I want to route www.abc.com to www.abc.app. Or if the user types in www.abc.com/hello then it will route to www.abc.app/hello. This is currently done via load balancer and creating an "A" record in Route53 connected to the load balancer
BUT I want to reserve a specific subdomain. Let’s say if the user types in www.abc.com/game, then I want it to display a NodeJS application that’s hosted in a separate EC2 server. The domain will not change and it will remain as www.abc.com/game.
Is this at all possible to do if the "A" record is already being taken by the load balancer?
2
Answers
No. This is not possible to do with DNS.
DNS servers simply convert the domain name (
www.abc.com
) to an IP address. The ‘path’ portion (/game
) is not sent to the DNS servers, so they cannot use that to change the DNS resolution process.You will either need to:
game.abc.com
), orYou could use an application load balancer and path based routing.
https://repost.aws/knowledge-center/elb-achieve-path-based-routing-alb
If your node app were amplify, you could use path based routing to /games.
https://docs.amplify.aws/javascript/build-a-backend/restapi/configure-rest-api/
You could use api gateway. Check out the Routing API requests, section.
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-routes.html
You could use CloudFront origins, too.
https://hitaha.medium.com/path-based-routing-on-aws-cloudfront-host-multiple-amplify-and-s3-apps-under-one-domain-3d47dda9e2c3