Amazon S3的重定向规则 - 让数据丢失重定向、数据丢失、规则、Amazon

2023-09-11 08:36:05 作者:深海

我们最近提出我们的网站到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。

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.

我发现,我们可以在Amazon S3中所描述上的 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.

有没有一种方法来定义S3重定向与转发/保持GET变量? 我们如何解决这个问题的最好?任何想法的?

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?

推荐答案

通过GET数据,这听起来像你指的查询字符串 - 例如: 富= 1&安培;巴= 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.

,你可以使用路由规则来重定向所有对象的请求与特定的preFIX到不同的网站,以及可选,你可以做到这一点重定向仅会出现错误(如404),而试图服务原始对象。使用这种方法,查询字符串似乎是始终如一preserved

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://其他站点。 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>

&LT; HTTPError这样codeReturnedEquals&GT; 如果你想重定向不需要的每次的匹配是preFIX对象请求其他的网站,即使对象已经存在在配置规则桶。 &LT; ReplaceKey prefixWith&GT; 可以设置为相同的值&LT;关键prefixEquals&GT; 或者可能完全省略,如果你不需要重写的路径preFIX。

<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.

请注意,你不会在preFIX相关选项使用斜线。

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

还要注意正确的值,你需要使用的&LT; HTTPError这样codeReturnedEquals&GT; 可能是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.