# Amazon S3 Redirect Rules Generator A Ruby script to generate simple Amazon S3 Redirection Rules XML file. **Update**: There is an app for that now! Use [Amazon S3 Redirector](http://quiet-cove-8872.herokuapp.com/) (Web app) and you can generate the XML without any knowledge about Ruby. Thanks to [@rainforestapp](https://github.com/rainforestapp/amazon-s3-redirects). BTW, [It's open source too](https://github.com/rainforestapp/amazon-s3-redirects). ## Dependencies * Nokogiri ## Usage ruby s3-routes-generator.rb input.txt The generated XML is printed to STDOUT. ## Assumptions on S3 Bucket It assumes that: 1. Website Hosting is enabled. 2. Index Document is set to `index.html`. ## Conversion Rules 1. For `target` path, if it ends with `/`, then `index.html` will be appended. 2. For `source` and `target` path, the leading `/` will be removed, because S3's object key does not begin with `/`. ## Sample Input One rule per line. Each rule is constructed by `source` and `target` path, spearated by at least 1 space. Please not that rules are matched using `KeyPrefixEquals`, and is First-In-First-Out, so if you have multiple redirections from same prefixes (typically `/dir` and `/dir/subdir`), please put the longer one before the shorter one, i.e. Depth-First. /home / /products/iphone/specs.html /iphone/specs.html /products/iphone/ /iphone/ /products/ipad/accessories/ /ipad/accessories.html /products/ipad/ /ipad/ /products / ## Sample Output ```xml home index.html products/iphone/specs.html iphone/specs.html products/iphone/ iphone/index.html products/ipad/accessories/ ipad/accessories.html products/ipad/ ipad/index.html products index.html ``` ## References * [Configure a Bucket for Website Hosting - Amazon Simple Storage Service](http://docs.aws.amazon.com/AmazonS3/latest/dev/HowDoIWebsiteConfiguration.html#configure-bucket-as-website-routing-rule-syntax) ## License None. I release this script to Public Domain.