Amazon S3 重定向规则 - 缺少 GET 数据 [英] Amazon S3 Redirect rule - GET data is missing

查看:33
本文介绍了Amazon S3 重定向规则 - 缺少 GET 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近将网站移至 Amazon S3(所有静态页面).我们将所有静态文件移至另一个子域,该子域仍指向我们的旧服务器.

We recently moved our website to Amazon S3 (all static pages). We moved al static files to a different subdomain which still points to our old server.

除了一件事外,一切都很好.

All is working lovely except one thing.

我们得到了一个脚本,该脚本仍在从主域上的旧客户端调用.在新客户端上,URL 是固定的,但旧客户端仍在使用旧 URL.

We got a script that's still being called from old clients on the main domain. On the new clients, the URL is fixed, but the old clients are still using the old URL.

我发现我们可以按照 http://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html.这是有效的,只是我们正在丢失所有 GET 变量.

I found we can manage redirects in Amazon S3 as described on http://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html . This is working, except the fact we are loosing all our GET-variables.

有没有办法通过转发/保留 GET 变量来定义 S3 重定向?我们怎样才能最好地解决这个问题?有什么想法吗?

Is there a way to define a S3 redirect with forwarding/keeping the GET-variables? How can we fix this problem the best? Any idea's?

推荐答案

通过获取数据",听起来您指的是查询字符串——例如?foo=1&bar=2 - 遵循您 URL 中的路径.当您执行对象级重定向时,这会被 S3 删除.

By "GET data," it sounds like you are referring to the query string -- e.g. ?foo=1&bar=2 -- that follows the path in your URL. This is removed by S3 when you do object-level redirects.

您可以使用 路由规则 将具有特定前缀的所有对象的请求重定向到不同的网站,并且您可以选择仅在尝试提供原始服务时发生错误(例如 404)时才执行此重定向目的.使用这种方法,查询字符串似乎始终保持不变.

Instead of redirecting specific objects, you can use routing rules to redirect requests for all objects with a specific prefix to a different web site, and optionally you can do this redirect only if an error (such as 404) would occur while trying to serve the original object. Using this method, the query string seems to be consistently preserved.

http://example.com/this/directory/* 中每个不存在的对象重定向到 http://other-site.example.com/that/directory/* 你会使用这样的规则:

To redirect every nonexistent object at http://example.com/this/directory/* to http://other-site.example.com/that/directory/* you'd use a rule something like this:

<RoutingRule>
    <Condition>
        <KeyPrefixEquals>this/directory/</KeyPrefixEquals>
        <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
        <Protocol>http</Protocol>
        <HostName>other-site.example.com</HostName>
        <ReplaceKeyPrefixWith>that/directory/</ReplaceKeyPrefixWith>
    </Redirect>
</RoutingRule>

如果您想将每个与该前缀匹配的对象请求重定向到另一个站点,即使该对象已经存在于其中的存储桶中,也不需要规则已配置. 可以设置为与 相同的值,或者可能完全省略,如果您不需要重写路径前缀.

<HttpErrorCodeReturnedEquals> is not required if you want to redirect every object request matching that prefix to the other site, even when the object already exists in the bucket where the rule is configured. <ReplaceKeyPrefixWith> could be set to the same values as <KeyPrefixEquals> or possibly omitted entirely, if you don't need to rewrite the path prefix.

请注意,在与前缀相关的选项中不要使用前导斜杠.

Note that you don't use a leading slash in the prefix-related options.

另请注意,您要为 <HttpErrorCodeReturnedEquals> 使用的正确值可能是 403(禁止")而不是 404(未找到").S3 中的对象可以通过存储桶级或对象级权限公开.如果存储桶本身不是公开可读的,则对象仍然可以公开读取,如果它们的权限是单独设置的.当存储桶本身不是公开可读的时,(iirc) S3 将不会确认对象是否存在,在未经身份验证的请求上会出现 404,而是会生成 403 错误,因此这是您需要捕获的错误在重定向规则中.

Note also that the correct value you'll want to use for <HttpErrorCodeReturnedEquals> may be 403 ("Forbidden") instead of 404 ("Not Found"). Objects in S3 can be made public by either bucket-level or object-level permissions. If the bucket itself is not publicly-readable, the objects still can be, if their permissions are set individually. When the bucket itself is not publicly-readable, (iirc) S3 will not acknowledge whether the object exists or not, with a 404 on an unauthenticated request, and will instead generate the 403 error, so that's the error you'll need to trap in the redirect rules.

这篇关于Amazon S3 重定向规则 - 缺少 GET 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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