title: How to redirect URL at AWS CloudFront?
body: <p>I have a client website that serves the images through AWS CloudFront and S3. The images are in PNG format and the URL on the webpage is of the CloudFront domain rather than the custom domain. In order to reduce costs, we are planning to compress them to JPG format. However, we have found that the image URL's are hardcoded in the database. </p>
  
  <p>The problem is when we compress the image to JPG, the file extension changes and thus the old URL will not work as it is. The client does not wants to make changes to the database right now. </p>
  
  <p>Is there a way we can serve the compressed files (with a different extension) for the same requests coming from the webpage?</p>
  
  <p>I was looking into a solution to route requests using Lambda Edge - <a href="https://aws.amazon.com/blogs/networking-and-content-delivery/dynamically-route-viewer-requests-to-any-origin-using-lambdaedge/" rel="nofollow noreferrer">https://aws.amazon.com/blogs/networking-and-content-delivery/dynamically-route-viewer-requests-to-any-origin-using-lambdaedge/</a> </p>
  
  <p>Is there any other optimal solution for this which you could suggest? Is there a way CloudFront to check for both types of file (jpg and png) in S3 and serve one of them? Example: request came for images/car.png -- > CloudFront to check for both images/car.png and images/car.jpg. If jpg exists serve this one.</p>