I want to redirect a url and their subdomains api.example.com/static/brands/*
to www.example.com/brands/*
. My goal is that when a client go in www.example.com/brands/*
the webpage seen is the webpage of api.example.com/static/brands/*
but the URL is www.example.com/brands/*
so it’s totally transparent for him.
The domain name api.example.com
is redirecting to an ALB.
I am a bit confused about what is the logic, how can I achieve this with Cloudfront?
2
Answers
You can use CloudFront Functions (lightweight JavaScript functions that execute at the edge). Here is an example reference of doing redirects based on country – you can modify based on your needs: https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/redirect-based-on-country
I believe what you want is to make a cloudfront distrobution for
www.example.com
Which has an origin
api.example.com/static/brands/
and a pattern path
/brands/*
which redirects all requests fromexample.com/brands/*
to the originapi.example.com/static/brands/