Skip to content

How to Rewrite/Redirect conditionally Multiple Domains in AWS CloudFront with S3 Static Content?

0

Good evening everyone!

My question is related to the possibility of a domain modification in the URL. The current infrastructure is a Cloudfront distribution with an S3 serving static content. The problem I am dealing with is based on a rewrite/redirect of the domain example.app.web.ex.es to web.example.com, example1.app.web.ex.es to web.example1.es and so on with different domain endings with the first domain always ending in app.web.ex.es.

From cloudfront it is not possible to do it and in the s3 redirection rules neither because it is not possible to condition it based on the domain. What solutions do you see for this problem? Is there any viable solution that maintains the scalability offered by cnd and s3?

2 Answers
0

CloudFront Functions fits better than Lambda@Edge.

Refer the below doc which mentions that Cloudfront Functions are ideal for URL redirects or rewrites

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-choosing.html

answered 2 years ago

  • First of all, like the colleague in the other reply, I would like to thank you so much for the answer you have posted.

    As I said in the other answer I already used the Cloudfront function with no successful result as I could not differentiate from which domain the user made the request as it always returned cdn.example.es as host.

    I hope this helps.

    Best regards, Daniel

  • I have used it to redirect when user enters xyz.app in browser and redirect to ex.abc.com and it works well. Probably you are checking the wrong field or something

  • None of the fields I print out from the entire request are useful. :(

0
  • CloudFront Functions fits better than Lambda@Edge.

    Refer the below doc which mentions that Cloudfront Functions are ideal for URL redirects or rewrites

    https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-choosing.html

  • First of all, thank you very much for your reply.

    I have tried with the Cloudfront function and when debugging I realised that as host I received cdn.example.es which is not useful for this case because it is necessary to know which exact domain it is so that it redirects/rewrites to its corresponding domain.

    I hope I have clarified this. Once again, I would like to express my sincere gratitude for your assistance.

    Best regards, Daniel

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.