重定向到 S3 子文件夹的 index.html [英] Redirect to index.html for S3 subfolder

查看:48
本文介绍了重定向到 S3 子文件夹的 index.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个域 example.com.我有一个名为 example.com 的 S3 存储桶,其中包含一个有效的 index.html 文件.现在我喜欢创建两个名为 oldnew 的子文件夹,每个子文件夹都包含一个单独版本的单页应用程序.请求 https://example.com/old(我喜欢在浏览器地址栏中输入请求时省略 index.html)将打开 indexold 子文件夹中的 .html 文件并请求 https://example.com/new 将打开 index.html.进行这些重定向的最佳方法是什么?我应该在 Route 53 example.com/old -> example.com/old/index.html 中设置一些东西,还是有更好的方法?>

解决方案

无需 lambda 函数即可增加项目的费用和复杂性.

以下答案引用自

您不需要从下拉列表中显示的存储桶中设置源,而是需要从其 S3 设置页面中获取该资源的静态 Web 托管端点并手动将其弹出.

使用 Cloudfront 分发源的静态源意味着对该分发的任何请求都将使用 S3 的根对象查找,并且您的 404 响应应该随着引用流过而消失.

重要

这样做之后:

否则,您所做的更改不会立即生效.

I have a domain example.com. I have a S3 bucket named example.com setup with an index.html file that works. Now I like to create two subfolders called old and new, each containing a separate version of a single page application. Requesting https://example.com/old (I like to omit the index.html when entering the request in address bar for browser) would open the index.html file in the old subfolder and requesting https://example.com/new would open the index.html. What is the best way of doing these redirects? Should I set something up in Route 53 example.com/old -> example.com/old/index.html or is there a better way of doing it?

解决方案

No need for a lambda function adding expense and complexity to your project.

The following answer is quoted from https://stevepapa.com/

https://stevepapa.com/my-great-new-post/ would be expected to work the same way as: https://stevepapa.com/my-great-new-post/index.html

There’s a clever little way to get these flowing through to the Cloudfront distribution, and it involves changing the source origin from the one that Cloudfront presents to you by default.

When selecting the origin source Cloudfront will show you a list of S3 buckets.

Instead of setting the source from the bucket shown in the dropdown list, you’ll need to grab the static web hosting endpoint for that resource from its S3 settings page and pop it in manually.

Using the static source for the Cloudfront distribution origin means any request to that distribution will be using the S3’s root object lookup, and your 404 responses should disappear as the references flow through.

Important

After doing this:

Otherwise, the changes you made won't go live immediately.

这篇关于重定向到 S3 子文件夹的 index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆