LoginSignup
1
0

More than 5 years have passed since last update.

【小ネタ】S3で404ページを全て特定のドキュメントにリダイレクトしたい

Posted at

S3でウェブサイトホスティングする際に、存在しないドキュメントへのアクセスを全て特定のパスにリダイレクトしたいケースがあったのでその時のメモ。

ルーティングルール等は公式ドキュメントが詳しい
https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/how-to-page-redirect.html

実際の設定

xml形式で、リダイレクトルールを設定する。

サンプル

例)存在しないドキュメントへのリクエストは、全てhogeにリダイレクトする。 ※hoge/index.htmlを設置する。

<RoutingRules>
  <RoutingRule>
    <Condition>   
      <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>      
      <ReplaceKeyPrefixWith>hoge</ReplaceKeyPrefixWith>
    </Redirect>
  </RoutingRule>
</RoutingRules>

A9F2128A-0064-4A7F-86F0-C5029933E9A4.png

動作イメージ

存在しないパスへのリクエスト https://hogehoge.com/abc.jpg

301リダイレクト

https://hogehoge.com/hoge/が表示される

1
0
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
1
0