Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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/が表示される

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away