S3 でホストしている静的 Web サイトのリニューアルを実施し、一部 URL が変更になりました。そこで、旧ページから新ページに 301 リダイレクトを設定したくなりました。
AWS マネージメントコンソールの日本語対応がされたので手順は日本語で書きます。
S3 の Management Console のバケットの一覧から「静的ウェブサイトホスティング」を選択し、「リダイレクトルールを編集する」を押します。
そこで出てきたテキストエリアに、リダイレクトルールの XML を書いていきます。具体的には下記のように、設定したい数だけ <RoutingRule>
要素を増やしていくことになります。
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>old-page-1.html</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>new-page-1/</ReplaceKeyPrefixWith>
<HttpRedirectCode>301</HttpRedirectCode>
</Redirect>
</RoutingRule>
<RoutingRule>
<Condition>
<KeyPrefixEquals>old-page-2.html</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>new-page-2/</ReplaceKeyPrefixWith>
<HttpRedirectCode>301</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>
今回の案件では Middleman を使っていたので、 builder で生成させてみました。
routing-rules.xml.builder
mappings = {
'old-page-1.html' => 'new-page-1/',
'old-page-2.html' => 'new-page-2/',
}
xml.RoutingRules do |routing_rules|
mappings.each do |from, to|
routing_rules.RoutingRule do |routing_rule|
routing_rule.Condition do |condition|
condition.KeyPrefixEquals from
end
routing_rule.Redirect do |redirect|
redirect.ReplaceKeyPrefixWith to
redirect.HttpRedirectCode 301
end
end
end
end
詳しくは下記に仕様があります。
賛否あるかとは思いますが、日本人のぼくにとって日本語で使えるツールやドキュメントが増えていくのは良いことですねー。