LoginSignup
7
7

More than 5 years have passed since last update.

Amazon Web Services (AWS) Simple Storage Service (S3) に画像が無い場合のみ、自サーバーへリダイレクトする方法

Last updated at Posted at 2013-07-23

'Static Web Hosting'設定を'Enable website hosting'のラジオボタンをチェックして
'Edit Redirection Rules'のテキストエリアに以下を入れる。

<RoutingRules>
    <RoutingRule>
        <Condition>
            <HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals >
        </Condition>
        <Redirect>
            <HostName>image.example.domain</HostName>
            <HttpRedirectCode>302</HttpRedirectCode>
        </Redirect>
    </RoutingRule>
</RoutingRules>

上記でS3にファイルが無い場合302でリダイレクトされる

http://{$s3domain}/foo/var/hoge.jpg -> http://image.example.domain/foo/var/hoge.jpg

詳しくは公式ドキュメントをご覧ください。

補足1.リダイレクトコード307

リダイレクトコードは様々だが、HttpRedirectCodeに307を指定する事によって、CloudFrontにもリダイレクトをキャッシュさせずにすむので、ファイルを置いたらすぐCloudFrontが認識したりできる。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7