Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redirect 如何将子目录重定向到外部url s3_Redirect_Amazon Web Services_Amazon S3 - Fatal编程技术网

Redirect 如何将子目录重定向到外部url s3

Redirect 如何将子目录重定向到外部url s3,redirect,amazon-web-services,amazon-s3,Redirect,Amazon Web Services,Amazon S3,我有一个旧网站,我正在移动到s3,除了一些页面我正在移动到另一个子域(不是s3)。它们有如下URL: http://www.example.com/2015/09/07/some-url 我想将其重定向到如下url: http://subdomain.example.com/2015/09/07/some-url 我似乎无法让它工作,以下是我的重定向规则: <RoutingRules> <RoutingRule> <Condition>

我有一个旧网站,我正在移动到s3,除了一些页面我正在移动到另一个子域(不是s3)。它们有如下URL:

http://www.example.com/2015/09/07/some-url

我想将其重定向到如下url:

http://subdomain.example.com/2015/09/07/some-url

我似乎无法让它工作,以下是我的重定向规则:

<RoutingRules>
<RoutingRule>
    <Condition>
        <KeyPrefixEquals>2015/09/07/some-url/</KeyPrefixEquals>
    </Condition>
    <Redirect>
        <Protocol>http</Protocol>
        <HostName>subdomain.example.com</HostName>
        <ReplaceKeyPrefixWith>2015/09/07/some-url/</ReplaceKeyPrefixWith>
    </Redirect>
</RoutingRule>

2015/09/07/一些url/
http
subdomain.example.com
2015/09/07/一些url/


此外,我是否必须在s3存储桶中实际创建空目录才能使规则工作?

您不需要空目录才能使其工作。但是,您可能确实希望删除尾部斜杠

<KeyPrefixEquals>2015/09/07/some-url/</KeyPrefixEquals>
2015/09/07/一些url/
…变成

<KeyPrefixEquals>2015/09/07/some-url</KeyPrefixEquals>
2015/09/07/一些url
如果需要,如果传入请求未提供,则通常会由目标服务器添加尾部斜杠

此外,除非值正在更改,否则不需要设置

从REST API设置页面重定向 以下AmazonS3API操作支持请求中的x-amz-website-redirect-location头。AmazonS3将对象元数据中的头值存储为x-amz-website-redirect-location

放置对象

启动多部分上传

POST对象

放置对象-复制

设置页面重定向时,可以保留或删除对象内容。例如,假设您的bucket中有一个page1.html对象

要保留page1.html的内容并仅重定向页面请求,您可以提交一个PUT Object-Copy请求,以创建一个新的page1.html对象,该对象使用现有的page1.html对象作为源。在请求中,设置x-amz-WEBSET-redirect-location头。请求完成后,原始页面的内容将保持不变,但AmazonS3会将页面的所有请求重定向到指定的重定向位置

要删除page1.html对象的内容并重定向页面请求,可以发送PUT对象请求以上载具有相同对象键的零字节对象:page1.html。在PUT请求中,将page1.html的x-amz-website-redirect-location设置为新对象。请求完成后,page1.html没有内容,请求被重定向到x-amz-website-redirect-location指定的位置

当您使用GET object操作以及其他对象元数据检索对象时,AmazonS3会在响应中返回x-amz-website-redirect-location头