如何在我的Cloudfront/S3托管的网页上进行301重定向一个单独页面?

huangapple go评论136阅读模式
英文:

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架构卡通捕捉了我的方法:

如何在我的Cloudfront/S3托管的网页上进行301重定向一个单独页面?

除了现有的逻辑外,我还想将一个单独的页面重定向到:

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:

如何在我的Cloudfront/S3托管的网页上进行301重定向一个单独页面?

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"
        }
    }
]

huangapple
  • 本文由 发表于 2023年2月19日 09:49:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497515.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定