{"id":625,"date":"2020-04-03T09:00:00","date_gmt":"2020-04-03T00:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/04\/03\/url_normalization_of_s3_website_with_lambda_at_edge"},"modified":"2020-04-03T09:00:00","modified_gmt":"2020-04-03T00:00:00","slug":"url_normalization_of_s3_website_with_lambda_at_edge","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/04\/03\/url_normalization_of_s3_website_with_lambda_at_edge\/","title":{"rendered":"\u9759\u7684\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u306b\u304a\u3051\u308bURL\u6b63\u898f\u5316\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u5b9f\u65bd"},"content":{"rendered":"
\u897f\u85e4\u3067\u3059\u3002<\/p>\n
\u9ad8\u53ef\u7528\u6027\u306e\u3042\u308b\u9759\u7684\u306a\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u3092\u5b9f\u73fe\u3057\u305f\u3044\u6642\u306b\u306f\u3001Amazon S3\u3068CloudFront\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u69cb\u7bc9\u3067\u304d\u307e\u3059\u3002 \u307e\u305f\u3001Amazon S3\u306e\u9759\u7684\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u306e\u6a5f\u80fd\u306e\u300c\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30eb\u30fc\u30eb\u300d\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u6b63\u898f\u8868\u73fe\u306b\u3088\u308b\u30eb\u30fc\u30eb\u8a2d\u5b9a\u3092\u30ab\u30d0\u30fc\u3057\u3066\u304a\u3089\u305a\u3001\u8a2d\u5b9a\u3059\u308b\u30eb\u30fc\u30eb\u6570\u304c\u81a8\u308c\u3066\u3057\u307e\u3044\u304c\u3061\u3067\u3059\u3002<\/p>\n \u305f\u3068\u3048\u3070\u3001 \u306e\u3088\u3046\u306b "index.html" \u306e\u6709\u308a\u3001\u306a\u3057\u3092\u63c3\u3048\u305f\u6b63\u898f\u5316\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u306f<\/p>\n \u306e\u3088\u3046\u306a\u5f62\u3067\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3057\u3066\u3044\u304f\u5fc5\u8981\u304c\u51fa\u3066\u304d\u307e\u3059\u3002<\/p>\n \u3057\u304b\u3057\u3001\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306eSEO\u3092\u8003\u3048\u308b\u4e0a\u3067\u306f\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30eb\u30fc\u30eb\u306f\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u3044\u306a\u304c\u3089\u306a\u308b\u3079\u304f \u305d\u3053\u3067\u4eca\u56de\u306fLambda@edge\u3092\u4f7f\u3063\u305f\u5f62\u3067\u3001<\/p>\n \u3068\u3044\u3046\u30b7\u30ca\u30ea\u30aa\u3067\u691c\u8a3c\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n S3 + CloudFront\u3067\u306e\u30a6\u30a7\u30d6\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u3084\u305d\u306e\u969b\u306bLambda@Edge\u3092\u4f7f\u3063\u305f\u5834\u5408\u306e\u4f5c\u308a\u65b9\u306e\u4f8b\u306a\u3069\u3064\u3044\u3066\u306f\u5f0a\u793e\u30d6\u30ed\u30b0\u306e<\/p>\n \u306a\u3069\u306b\u3082\u3054\u3056\u3044\u307e\u3059\u306e\u3067\u3001\u5272\u611b\u3057\u307e\u3059\u3002 Lambda@Edge\u306e\u69cb\u7bc9\u65b9\u6cd5\u306f\u7701\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u65e9\u901f\u30b3\u30fc\u30c9\u4f8b\u3068\u3057\u307e\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n \u5177\u4f53\u7684\u306a\u6d41\u308c\u3068\u3057\u3066\u306f<\/p>\n \u3068\u3044\u3046\u5f62\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002 <\/p>\n \u3068\u3044\u3046\u3088\u3046\u306b \uff08\u30fb\u30fb\u30fb\u86c7\u8db3\u3067\u3059\u304c\u3001\u521d\u3081\u306f "index.html" \u3092 ""\uff08\u7a7a\u767d\uff09\u306b\u7f6e\u304d\u63db\u3048\u3088\u3046\u3068\u3057\u3066\u3001\u3046\u307e\u304f\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u52b9\u3044\u3066\u304f\u308c\u305a\u3001\u3064\u307e\u3065\u3044\u3066\u3044\u307e\u3057\u305f\u3002 \u4ee5\u4e0a\u304cURL\u6b63\u898f\u5316\u306e\u6e96\u5099\u3067\u3059\u3002\u6b21\u306bS3\u4e0a\u306b\u69cb\u7bc9\u3057\u305f\u30b5\u30a4\u30c8\u306e\u5185\u5bb9\u3068\u30a2\u30af\u30bb\u30b9\u3057\u305f\u969b\u306e\u52d5\u4f5c\u3092\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n \u69cb\u7bc9\u3057\u305f\u30b5\u30a4\u30c8\u306e\u5185\u5bb9\u306f\u3053\u306e\u3088\u3046\u306a\u5f62\u3067\u3059\u3002<\/p>\n <\/p>\n \u3068\u3044\u3046\u5177\u5408\u3067\u3059\u3002<\/p>\n \u3067\u306f\u3001\u307e\u305a\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u3001<\/p>\n \u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u52b9\u3044\u3066\u3044\u306a\u3044\u72b6\u614b\u3067\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n <\/p>\n <\/p>\n index.html\u304c\u3042\u308b\u5834\u5408\u3001\u306a\u3044\u5834\u5408\u3069\u3061\u3089\u3068\u3082\u540c\u3058\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n <\/p>\n <\/p>\n \u3053\u3061\u3089\u3082index.html\u6709\u308a\u7121\u3057\u3069\u3061\u3089\u3082\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n \u3067\u306f\u3001\u9069\u7528\u524d\u306e\u72b6\u6cc1\u304c\u308f\u304b\u3063\u305f\u3053\u3068\u3067\u5404\u30d1\u30bf\u30fc\u30f3\u3092\u8a66\u3057\u307e\u3059\u3002 \u2192 index.html\u7121\u3057\u306e\u5f62\u3067\u30b5\u30a4\u30c8\u30c9\u30e1\u30a4\u30f3\u540d\u76f4\u4e0b\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8<\/p>\n \u2192 index.html\u7121\u3057\u306e\u5f62\u3067 \u2192 index.html\u7121\u3057\u306e\u5f62\u3067 \u2192 index.html\u7121\u3057\u306e\u5f62\u3067 \u3069\u306e\u968e\u5c64\u306b\u304a\u3044\u3066\u3082\u5e0c\u671b\u901a\u308a\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u52b9\u3044\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n \u4ee5\u4e0a\u306e\u3088\u3046\u306b\u3001S3\u306e\u300c\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30eb\u30fc\u30eb\u300d\u306e\u8a2d\u5b9a\u3092\u5404\u968e\u5c64\u3054\u3068\u306b\u8db3\u3057\u5408\u308f\u305b\u3066\u884c\u304b\u306a\u304f\u3066\u3082\u3001index.html\u6709\u308a\u7121\u3057\u306eURL\u6b63\u898f\u5316\u304c\u5b9f\u73fe\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n \u4eca\u56de\u306e\u3088\u3046\u306aindex.html\u6709\u308a\u7121\u3057\u306eURL\u6b63\u898f\u5316\u306e\u30b7\u30ca\u30ea\u30aa\u306b\u9650\u3089\u305a\u3001\u3055\u307e\u3056\u307e\u306a\u30d1\u30bf\u30fc\u30f3\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u5b9f\u88c5\u3059\u308b\u969b\u306e\u53c2\u8003\u306b\u306a\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" \u306f\u3058\u3081\u306b \u897f\u85e4\u3067\u3059\u3002 \u9ad8\u53ef\u7528\u6027\u306e\u3042\u308b\u9759\u7684\u306a\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u3092\u5b9f\u73fe\u3057\u305f\u3044\u6642\u306b\u306f\u3001Amazon S3\u3068CloudFront\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u69cb\u7bc9\u3067\u304d\u307e\u3059\u3002 \u305f\u3060\u3057\u3001\u305d\u306e\u3088\u3046\u306a\u69cb\u6210\u3092\u53d6\u3063\u305f\u3068\u304d\u306b\u306f\u305f\u3068\u3048\u3070Apache\u30b5\u30fc\u30d0\u30fc\u3067\u69cb\u7bc9\u3057\u305f\u6642\u306e\u3088\u3046\u306a .htaccess\u3092\u4f7f\u3063\u305f\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u8a2d\u5b9a\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002 \u307e\u305f\u3001Amazon S3\u306e\u9759\u7684\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u306e\u6a5f\u80fd\u306e\u300c\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30eb\u30fc\u30eb\u300d\u3082\u3042 […]<\/p>\n","protected":false},"author":6,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,21],"tags":[321,136],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/625"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=625"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/625\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n\u305f\u3060\u3057\u3001\u305d\u306e\u3088\u3046\u306a\u69cb\u6210\u3092\u53d6\u3063\u305f\u3068\u304d\u306b\u306f\u305f\u3068\u3048\u3070Apache\u30b5\u30fc\u30d0\u30fc\u3067\u69cb\u7bc9\u3057\u305f\u6642\u306e\u3088\u3046\u306a .htaccess<\/code>\u3092\u4f7f\u3063\u305f\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u8a2d\u5b9a\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n
\nexample.com\/test\/index.html<\/code>\u306f
example.com\/test\/<\/code><\/p>\n
example.com\/test2\/index.html<\/code>\u306f
example.com\/test2\/<\/code><\/p>\n
\n
\n\u30b7\u30f3\u30d7\u30eb\u306b\u5b9f\u73fe\u3057\u305f\u3044\u3082\u306e\u3067\u3059\u3002<\/p>\n\n
\u69cb\u6210<\/h2>\n
\n
\n\u3053\u308c\u3089\u306e\u8a18\u4e8b\u3082\u305c\u3072\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\nLambda\u306e\u5185\u5bb9<\/h2>\n
'use strict';\nexports.handler = (event, context, callback) => {\n console.log("=====Redirection to the URL without index.html =====");\n\n \/\/ Get request and request headers\n const request = event.Records[0].cf.request;\n const headers = request.headers;\n\n \/\/ If URL ends with index.html, redirect to URL without index.html.\n const isIndex = request.uri.endsWith('\/index.html');\n if (isIndex) {\n console.log("=====Because the URL ends with index.html , redirect to the URL without index.html =====");\n const withoutIndex = request.uri.replace(\/\/index.html$\/, '\/');\n const response = {\n status: '301',\n statusDescription: 'Moved Permanently',\n headers: {\n location: [{\n key: 'Location',\n value: withoutIndex\n }]\n },\n };\n callback(null, response);\n console.log("=====Redirection to the URL without index.html has ended =====");\n }\n \/\/ Continue request processing if requested URL doesn't end with index.html\n callback(null, request);\n};\n<\/code><\/pre>\n
\n
\/index.html<\/code>\u3067\u3042\u308b\u304b\u3092\u78ba\u8a8d<\/li>\n
\/index.html<\/code>\u3092
\/<\/code>\u306b\u7f6e\u304d\u63db\u3048\u305f\u5f62\u306e
Location<\/code>\u306e\u5024\u3092\u6301\u3063\u305f\u30ec\u30b9\u30dd\u30f3\u30b9\u30d8\u30c3\u30c0\u30fc\u3092\u751f\u6210\u3057\u3066\u8fd4\u3059<\/li>\n
\n\u3053\u308c\u3092<\/p>\nview-request<\/code>\u3092\u8d77\u70b9\u306b\u3053\u306eLambda\u95a2\u6570\u304c\u52d5\u4f5c\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3067\u3001URL\u6b63\u898f\u5316\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002<\/p>\n
\n""\uff08\u7a7a\u767d\uff09\u306b\u3057\u3066\u3057\u307e\u3046\u3068\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u30d8\u30c3\u30c0\u30fc\u306eLocation<\/code>\u306e\u5024\u304c\u306a\u3044\u3053\u3068\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3053\u3068\u3067\u3046\u307e\u304f\u884c\u304b\u306a\u304b\u3063\u305f\u3088\u3046\u3067\u3059\u3002\uff09<\/p>\n
S3\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306e\u5185\u5bb9<\/h2>\n
\n
a<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bindex.html<\/li>\n
b<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bindex.html<\/li>\n
b<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4e2d\u306b\u3042\u308b
c<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bindex.html<\/li>\n<\/ul>\n
\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u52b9\u3044\u3066\u3044\u306a\u3044\u5834\u5408<\/h2>\n
\n
\u30b5\u30a4\u30c8\u76f4\u4e0b\u306eindex.html\uff08\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u7121\u3057\uff09<\/h3>\n
b\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306ec\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306eindex.html\uff08\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u7121\u3057\uff09<\/h3>\n
\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u52b9\u3044\u305f\u5834\u5408<\/h2>\n
\n\u898b\u3048\u65b9\u306f\u5909\u308f\u3089\u306a\u3044\u306e\u3067\u3001\u7d50\u679c\u3060\u3051\u3092\u30fb\u30fb\u30fb\u3002<\/p>\n\u30b5\u30a4\u30c8\u76f4\u4e0b\u306eindex.html<\/h3>\n
a<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306eindex.html<\/h3>\n
a<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30d1\u30b9\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8<\/p>\n
b<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306eindex.html<\/h3>\n
b<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30d1\u30b9\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8<\/p>\n
b<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4e2d\u306b\u3042\u308b
c<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bindex.html<\/h3>\n
c<\/code>\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30d1\u30b9\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8<\/p>\n
\u307e\u3068\u3081<\/h2>\n