0
votes

For a url of the form

https://www.example.com/i/http://some-image-url.png

Is it possible to redirct to http://some-image-url.png (param after i/)?

with just Editing Redirection rule of AWS S3 bucket website.

<RoutingRules>
<RoutingRule>
    <Condition>
        <KeyPrefixEquals>i/</KeyPrefixEquals>
    </Condition>
    <Redirect>
        [[config for redirecting to http://some-image-url.png]]
    </Redirect>
</RoutingRule>

Doc Link: http://docs.aws.amazon.com/AmazonS3/latest/dev/HowDoIWebsiteConfiguration.html#configure-bucket-as-website-routing-rule-syntax

1
What's the use case for a configuration like this?Michael - sqlbot
I need to serve third party media files over https(read cloudFront).Ratan Kumar
Okay, so... use CloudFront, with the remote server specified as the origin server... not S3. S3 redirects aren't going to help you -- they're redirects -- not reverse proxying, and CloudFront doesn't follow the redirect, it just returns the redirect back to the browser.Michael - sqlbot
"CloudFront doesn't follow the redirect" this is exactly what I want. let S3 redirect, cloudfront URL will be constant for media.Ratan Kumar
No, I don't think this is what you want. Note carefully: If S3, behind CloudFront, returns a redirect response, CloudFront does not follow the redirect, which means CloudFront does not fetch the content and return it to the browser. CloudFront, instead, sends the redirect response message (with the new URL in the Location header) all the way back to the browser, requiring the browser to follow the redirect, which means the browser is required to directly fetch the content from the alterate URL. That, I believe, is actually the exact opposite of what you want.Michael - sqlbot

1 Answers

1
votes

From experience, albeit last year, the routing rules and conditions do not allow wildcards, however you can redirect to a different host, so you would have to do something like

<?xml version="1.0"?>
<RoutingRules>
  <RoutingRule>
    <Condition>
      <KeyPrefixEquals>i/http://some.image.host/some-image.png</KeyPrefixEquals>
    </Condition>
    <Redirect>
      <HostName>some.image.host</HostName>
      <ReplaceKeyPrefixWith>some-image-url.png</ReplaceKeyPrefixWith>
  </RoutingRule>
</RoutingRules>