Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 static host redirect and strip slug

Tags:

amazon-s3

Is it possible to create a static website redirect rule that redirects www.domain1.com/* --> www.domain2.com without maintaining the slug ?

Something like this if wildcard was allowed:

<RoutingRules>
  <RoutingRule>
  <Condition>
    <KeyPrefixEquals>*</KeyPrefixEquals>
  </Condition>
  <Redirect>
    <HostName>www.domain2.com</HostName>
    <ReplaceKeyPrefixWith>/</ReplaceKeyPrefixWith>
  </Redirect>
  </RoutingRule>
</RoutingRules>
like image 349
Michael Avatar asked Oct 28 '16 08:10

Michael


1 Answers

You have to "think like S3."

"Key prefix" is a prefix, and by definition, an empty string is the prefix of all strings -- because left(anystring,len('')) == ''.

So you don't need a wildcard -- you should be able to simply say this:

<KeyPrefixEquals></KeyPrefixEquals>

Then, you don't want to replace the prefix -- you want to replace the entire key, so that looks like this:

<ReplaceKeyWith></ReplaceKeyWith>

You ask... why is it empty instead of /?

It's because, in the S3 model, the keyspace does not begin with /. bucket.example.com/foo has a path of /foo but its key is actually foo.

like image 105
Michael - sqlbot Avatar answered Oct 14 '22 08:10

Michael - sqlbot