简体   繁体   English

Cloudfront 不断将我重定向到 index.html

[英]Cloudfront keeps redirecting me to index.html

I have a static website uploaded on S3 and recently I came to use Cloudfront as I wanted to serve it with https.我在 S3 上上传了一个 static 网站,最近我开始使用 Cloudfront,因为我想用 https 为它服务。 Now my problem is that I have some js logic that based on the path, puts a "#" and scrolls around, but now for some reason it redirects me to mysite.com/index.html and breaks me the logic.现在我的问题是我有一些基于路径的 js 逻辑,放置一个“#”并滚动,但现在由于某种原因它将我重定向到 mysite.com/index.html 并打破了我的逻辑。

I would like how to avoid this behaviour, just as in localhost, with the base path "/" without any index.html at the end of it.我想如何避免这种行为,就像在 localhost 中一样,基本路径“/”没有任何 index.html 在它的末尾。

I've tried to set Default Root Object to "/" only but it seems to ignore it and keep redirecting, also I tried to invalidate it but nothing.我试图将默认根 Object 设置为“/”,但它似乎忽略它并继续重定向,我也试图使其无效但没有。

Also I have to say that I'm using 2 S3 buckets one with the "www" which redirects to the previously mentionated, for that reason I also created 2 cloudfront distributions.另外我不得不说我正在使用 2 个 S3 存储桶,其中一个带有“www”,它重定向到前面提到的,因此我还创建了 2 个云端分发。

Idk what im doing wrong but something has to be:S我知道我做错了什么,但必须是:S

You need to specify a default Root object with the object name.您需要使用 object 名称指定默认根 object。

example: www.bucket1.tld/ (redirects to naked domain).bucket1.tld/ index.html <---- you need to specify this as the default root object, not "/"示例: www.bucket1.tld/ (重定向到裸域).bucket1.tld/ index.html <----您需要将其指定为默认根 object,而不是“/”

Your bucket can't find the default root object because "/" is a prefix, not an object.您的存储桶找不到默认根 object,因为“/”是前缀,而不是 object。 The redirect from www to naked domain is seperate from this and is working as intended.从 www 到裸域的重定向与此分开,并且按预期工作。

Additionally - The bucket that is setup as the website is the one causing the "index.html" to be strapped to the back of your domain.此外 - 设置为网站的存储桶是导致“index.html”被捆绑到您的域后面的存储桶。 This is because you've told S3 that the bucket is a website and that it needs to serve "index.html" as a default object.这是因为您告诉 S3 存储桶是一个网站,并且它需要将“index.html”作为默认 object 提供服务。

Set your DRO to "index.html" in CloudFront.在 CloudFront 中将您的 DRO 设置为“index.html”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM