重定向到S3子文件夹的index.html [英] Redirect to index.html for S3 subfolder
问题描述
我有一个域 example.com
。我有一个名为 example.com
的S3存储桶,其中的 index.html
文件有效。现在,我想创建两个名为 old
和 new
的子文件夹,每个子文件夹包含一个单页应用程序的单独版本。请求 https://example.com/old
(我想在 index.html
中输入请求时省略浏览器的地址栏)将打开 old
子文件夹中的 index.html
文件,并请求 https://example.com/new
将打开 index.html
。进行这些重定向的最佳方法是什么?我应该在53号公路上设置什么内容 example.com/old
-> example.com/old/index.html
还是有更好的方法?
不需要lambda函数,这会增加项目的费用和复杂性。 / p>
以下答案引自
您需要从静态列表中获取静态信息,而不是从下拉列表中显示的存储桶中设置源该资源的S3设置页面中的Web托管端点,然后手动将其弹出。
使用Cloudfront发行源的静态源意味着对该发行版的任何请求都将使用S3的根目录对象查找,并且您的404响应应该在引用流经时消失。
重要提示:
执行此操作之后,清除浏览器缓存并取消对Cloudfront发行中的项目的验证。否则,您所做的更改将不会立即生效。
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, clear your browser cache and devalidate the items in your cloudfront distribution. Otherwise, the changes you made won't go live immediately.
这篇关于重定向到S3子文件夹的index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!