title: Device based redirection on CloudFront serving from S3 origin
body: <p>Is there a way to redirect the user to the mobile version of a web app say <code>m.foobar.com</code> based on the <code>User Agent</code> header using CloudFront?</p>
  
  <p>I did read up on header caching using the user's device type using <code>CloudFront-Is-Mobile-Viewer</code> header. But, I can only whitelist it if I'm using a custom origin to serve my assets (ELB or an EC2 instance). In such a scenario, I could edit my server configuration to handle the redirection. </p>
  
  <p>However, I'm using S3 to serve my application now and would prefer a solution within the CloudFront/S3 ecosystem.</p>
  
  <p><em>Edit:</em>
  For S3 distributions, I DONOT have access to the <code>CloudFront-Is-Mobile-Viewer</code> and other CF headers.
  <a href="https://i.stack.imgur.com/c4QaL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c4QaL.png" alt="This is all that&#39;s available"></a></p>
  
  <p>Any help, pointers would be greatly appreciated!</p>
  
  <p>Background Material: <a href="http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html" rel="nofollow noreferrer">http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html</a>
  <a href="https://aws.amazon.com/blogs/aws/enhanced-cloudfront-customization/" rel="nofollow noreferrer">https://aws.amazon.com/blogs/aws/enhanced-cloudfront-customization/</a></p>