英文:
How do I 301 redirect a single page on my Cloudfront/ S3 hosted web page?
问题
我使用AWS Cloudfront + S3解决方案托管我的网站。
我将所有裸域和纯HTTP请求重定向到前缀https://www.example.com。
以下S3 Cloudfront架构卡通捕捉了我的方法:
除了现有的逻辑外,我还想将一个单独的页面重定向到:
https://www.example.com/category/coins/
到
https://www.example.com/cat/coins.html
我尝试通过S3存储桶的重定向规则来实现这一点,但收到了一个301重定向到存储桶地址,而不是Cloudfront终端点。
例如:
http://www.example.com.s3-website-us-east-1.amazonaws.com/cat/coins.html
我该如何正确地重定向这个特定页面?
英文:
I use an AWS Cloudfront + S3 solution to host my website.
I redirect all naked domain and vanilla HTTP requests to the prefix https://www.example.com.
The following S3 Cloudfront Architecture cartoon captures my approach:
In addition to the existing logic, I would like to also redirect a single page, namely:
https://www.example.com/category/coins/
to
https://www.example.com/cat/coins.html
I tried to do this via the S3 buckets redirect rules and received a 301 redirect to the bucket address, and not the cloudfront endpoint.
e.g.
http://www.example.com.s3-website-us-east-1.amazonaws.com/cat/coins.html
How can I correctly redirect this particular page?
答案1
得分: 1
AWS提供了有关如何使用CloudFront进行重定向以及查看器请求功能的文档。
S3也有文档介绍如何基于不同主机执行重定向操作:
-
在S3中配置主机名(S3 -> 属性 -> 静态网站托管 -> 主机名)。这可能会重写域部分(我不是100%确定)。
-
高级重定向规则允许将路径替换为不同的键,这应该绝对有效。页面上有一个示例符合问题的情况。
英文:
AWS provides documentation on how to redirect with CloudFront and that are Viewer Request Functions.
S3 also has documentation on how to do redirects based on different hosts
-
Configure Host name in S3 (S3 -> Properties -> Static website hosting -> Host name). This may rewrite the domain part (I'm not 100% sure)
-
Advanced redirection rules allow to replace paths with different keys which should definitely work. There is an example on the page that fits the question
答案2
得分: 0
[
{
"Condition": {
"KeyPrefixEquals": "category/data-science"
},
"Redirect": {
"HostName": "john.soban.ski",
"Protocol": "https",
"ReplaceKeyWith": "cat/data-science.html"
}
},
{
"Condition": {
"KeyPrefixEquals": "category/coins"
},
"Redirect": {
"HostName": "john.soban.ski",
"Protocol": "https",
"ReplaceKeyWith": "cat/coins.html"
}
},
{
"Condition": {
"KeyPrefixEquals": "category/ietf"
},
"Redirect": {
"HostName": "john.soban.ski",
"Protocol": "https",
"ReplaceKeyWith": "cat/ietf.html"
}
},
{
"Condition": {
"KeyPrefixEquals": "category/howto"
},
"Redirect": {
"HostName": "john.soban.ski",
"Protocol": "https",
"ReplaceKeyWith": "cat/howto.html"
}
}
]
英文:
I used the following to redirect certain pages:
[
{
"Condition": {
"KeyPrefixEquals": "category/data-science"
},
"Redirect": {
"HostName": "john.soban.ski",
"Protocol": "https",
"ReplaceKeyWith": "cat/data-science.html"
}
},
{
"Condition": {
"KeyPrefixEquals": "category/coins"
},
"Redirect": {
"HostName": "john.soban.ski",
"Protocol": "https",
"ReplaceKeyWith": "cat/coins.html"
}
},
{
"Condition": {
"KeyPrefixEquals": "category/ietf"
},
"Redirect": {
"HostName": "john.soban.ski",
"Protocol": "https",
"ReplaceKeyWith": "cat/ietf.html"
}
},
{
"Condition": {
"KeyPrefixEquals": "category/howto"
},
"Redirect": {
"HostName": "john.soban.ski",
"Protocol": "https",
"ReplaceKeyWith": "cat/howto.html"
}
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论