문제

S3-Object에 리디렉션 헤더를 넣을 수 있습니까? 301 리디렉션처럼.

예를 들어:

mybucket.amazon-aws.com/myobject --> example.com/test

바람직하게는 객체에서 이와 같은 헤더를 설정하여 다음과 같습니다.

HTTP/1.1 301 Moved Permanently
Location: http://example.com/test
Content-Type: text/html
Content-Length: 0
도움이 되었습니까?

해결책

지난 달 에이 기능이 방금 추가되었습니다.

API 문서를 여기에서 찾을 수 있습니다.

http://docs.amazonwebservices.com/amazons3/latest/dev/how-to-page-redirect.html

당신이 당신의 객체를 넣을 때, 당신은 x-amz-website-redirect-location 사용하려는 301 리디렉션에 해당 객체에 대한 키.

콘솔을 사용할 수도 있습니다.

enter image description here

다른 팁

버킷에 웹 사이트 호스팅이 활성화 된 경우 301 리디렉션을 추가하는 대안적인 방법이 있습니다. IT에 따르면 리디렉션 규칙은 XML-Format의 버킷 레벨에 설명되어 있으며 AWS S3 콘솔 (정적 웹 사이트 호스팅 섹션)을 통해 버킷의 속성에 지정할 수 있습니다. 현재 구문에 대한 전체 문서를 찾을 수 있습니다 여기.

이 접근법은 한 곳에서 모든 리디렉션을 쉽게 관리하는 한 방대한 URL 이동이있을 때 편리합니다. 예를 들어 리디렉션 규칙을 정의 할 수 있습니다

<RoutingRule>
    <Condition>
        <KeyPrefixEquals>index.php</KeyPrefixEquals>
    </Condition>
    <Redirect>
        <ReplaceKeyWith>index.html</ReplaceKeyWith>
    </Redirect>
</RoutingRule>
<RoutingRule>
    <Condition>
        <KeyPrefixEquals>blog.php?id=21</KeyPrefixEquals>
    </Condition>
    <Redirect>
        <ReplaceKeyWith>mysql-utf-8-database-creation-snippet.html</ReplaceKeyWith>
    </Redirect>
</RoutingRule>

가짜 객체를 만들고 X-Amz-Website-Redirect-Location 메타 데이터를 지정하는 것과 동일합니다. 나쁜 소식은 XML에 하나의 버킷에 대해 50 개를 넘지 않을 수 있다는 것입니다. 그렇습니다. XML을 관리하는 것은 편리하지 않습니다. 그러나 나에게는 이런 식으로 현재 더 쉽습니다. 다시 한 번, 한 곳에서 모든 파일을 관리하기가 더 쉽기 때문입니다.

이 XML 접근 방식은 많은 페이지가있는 디렉토리로 이름을 바꿀 때 매우 유용합니다. 이 경우 내부의 각 페이지에 대해 별도의 규칙 대신 디렉토리에 대한 단일 리디렉션 규칙을 작성해야합니다. 예를 들어

<RoutingRule>
    <Condition>
        <KeyPrefixEquals>blog/</KeyPrefixEquals>
    </Condition>
    <Redirect>
        <ReplaceKeyPrefixWith>it-blog/</ReplaceKeyPrefixWith>
    </Redirect>
</RoutingRule>

이 규칙에 따르면 example.com/blog/whatever 방향을 바꿀 것입니다 example.com/it-blog/whatever.

이러한 접근법의 또 다른 유용한 특징은 접두사 만 대체한다는 것입니다. 디렉토리와 같은 방식으로 페이지를 리디렉션 할 수는 있지만 쿼리 매개 변수를 저장하십시오. 이러한 쿼리 매개 변수의 JS 처리가 있으면 적합 할 수 있습니다. x-amz-website-redirect-location metadata를 사용하면 아마도 그것을 잃을 것입니다.

내가 언급했듯이 XML을 쓰고 읽는 것은 불편할 수 있습니다. 이것을 극복하기 위해 나는 썼다 간단한 온라인 도구 GWT에서 일반 텍스트를 이전 및 새 URL을 XML 형식으로 변환합니다. 사용합니다KeyPrefixEquals 술어와 실행 ReplaceKeyPrefixWith 리디렉션.

마지막으로,에 따르면 선적 서류 비치, 웹 사이트 호스팅이 비활성화 된 경우이 버킷에는 리디렉션 지원이 적용되지 않습니다.

편집 :이 기능은 이제 AWS에서 기본적이므로 위의 답변을 참조하십시오.

실제로는 아닙니다. 이를 허용하는 내장 기능이 없지만, 할 수있는 것은 객체를 만드는 것이며 HTML로 저장하지 않더라도 HTML 파일로 적용 할 수 있습니다.

예를 들어:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Refresh" content="0; URL=http://www.example.com/target/">
    <title>Redirect</title>
</head>

<body>
    <a href="http://www.example.com/target/">http://www.example.com/target/</a>
</body>
</html>

이 페이지를보십시오. 소스를 빨리보십시오.

소스보기:http://carltonbale.com.s3.amazonaws.com/distance_chart.png

여기에서 설명을 볼 수 있습니다.

점 8 : http://carltonbale.com/9-hidden-features-of-amazon-s3

htaccess 301에서 Amazon S3 리디렉션 번역


htaccess 스타일 :

Redirect 301 /old/old.html http://www.new.com/new/new.html

변환 :

<RoutingRule>
    <Condition>
        <KeyPrefixEquals>old/old.html</KeyPrefixEquals>
    </Condition>
    <Redirect>
        <HostName>www.new.com</HostName>
        <Protocol>http</Protocol>
        <HttpRedirectCode>301</HttpRedirectCode>
        <ReplaceKeyWith>new/new.html</ReplaceKeyWith>
    </Redirect>
</RoutingRule>

당신은 아마도 다음의 줄을 따라 작은 스크립트를 쓸 수 있습니다.

// -----------------
// Javascript
// htaccess to amazon s3 redirect for static s3 websites.
// (XML goes into S3 Bucket Properties Editor > [x] Enable website hosting > Edit Redirection Rules box.)
// -----------------

var list = [
    "Redirect 301 /old/old-1.html http://www.new.com/new/new-1.html",
    "Redirect 301 /old/old-2.html http://www.new.com/new/new-2.html",
    "Redirect 301 /old/old-3.html http://www.new.com/new/new-3.html"
];

var output = [];

output.push('<?xml version="1.0"?>');
output.push('<RoutingRules>');

for(var i=0; i<list.length; i++){

    var item = list[i].replace("Redirect 301 /", "").split(" ");
    var oldLoc = item[0];
    var newLoc = item[1];

    output.push("   <RoutingRule>");
    output.push("       <Condition>");
    output.push("           <KeyPrefixEquals>" + oldLoc + "/KeyPrefixEquals>");
    output.push("       </Condition>");

    output.push("       <Redirect>");
    if(newLoc.substr(0, 1) == "/"){

        output.push("           <ReplaceKeyWith>" + newLoc + "</ReplaceKeyWith>");

    } else {

        var splitNewLoc = newLoc.replace("http://", "").split("/");
        var host = splitNewLoc.shift();
        var path = splitNewLoc.join("/");

        output.push("           <HostName>" + host + "</HostName>");
        output.push("           <Protocol>http</Protocol>");
        output.push("           <HttpRedirectCode>301</HttpRedirectCode>");

        if(path){
            output.push("           <ReplaceKeyWith>" + path + "</ReplaceKeyWith>");
        }

    }

    output.push("       </Redirect>");
    output.push("   </RoutingRule>");

}

output.push('</RoutingRules>');

print(output.join("\n"));

경고 : Amazon은 리디렉션 규칙 수를 50으로 제한합니다.

awscli 지금 쉽게 할 수 있습니다 (일종의)

  1. 버킷이 100% 공개되어 있는지 확인하십시오
  2. 버킷이 웹 사이트 호스팅 모드에 있는지 확인하십시오
  3. 전체 URL을 사용하여 사이트 만 참조하십시오 https://<bucket_name>.s3-website-<region>.amazonaws.com
  4. 사용 s3api 리디렉션을 설정하려면 호출하십시오

    AWS S3API PUT-OBJECT -ACL Public-Read--website-redirect-location "http://other-location.com"-버킷 foo-bucket -key 어딘가/블라

메모: 301 만 제공하고 리디렉션하기 때문에 S3에 어떤 개체도 게시하지 않습니다. Location 헤더.

테스트

curl -v 2 -L https://<bucket_name>.s3-website-<region>.amazonaws.com/somewhere/blah

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top