A Ruby script to generate simple Amazon S3 Redirection Rules.
Nokogiri
ruby s3-routes-generator.rb input.txt
The generated XML is printed to STDOUT.
/home /
/products/iphone /iphone
/products /
<?xml version="1.0"?>
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>home</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyWith>index.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
<RoutingRule>
<Condition>
<KeyPrefixEquals>products/iphone</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyWith>iphone</ReplaceKeyWith>
</Redirect>
</RoutingRule>
<RoutingRule>
<Condition>
<KeyPrefixEquals>products</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyWith>index.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
</RoutingRules>
It assumes that:
- Website Hosting is enabled.
- Index Document is set to
index.html.
None. I release this script to Public Domain.
Is it possible to detect user agent from the request and redirect based on the user agent on amazon s3 static hosting?