Amazon Web Services (AWS) Simple Storage Service (S3) is a really economical way of hosting static websites. With advanced “redirection rules” support, a static blog, even with legacy permalinks, can be hosted completely on AWS S3. When configured with CloudFront and CloudFlare, full SSL support for your own custom certificates can be used.
Prior to S3 supporting advanced redirection rules, there was only a binary option to redirect all requests to a specified hostname. While this feature is useful for handling blanket redirections, but useless if you need selective redirection like what a
.htaccess file can do, it is insufficient for site that have legacy permalinks to maintain.
Fortunately, S3’s advanced redirect rules allows you to somewhat mimic a subset of what an Apache
.htaccess file can do: 1) substitute the hostname; and/or 2) substitute the path, based on 2 possible conditions: a) HTTP error codes from S3, and/or b) request path prefix, albeit with a clumsy XML syntax. With a good text-editor with XML intelligence, it’s not too challenging to hand-craft.
Thanks to this feature, I’ve managed to set up redirect rules to map permalinks from my previous blog engine to the current permalinks layout.
To begin, assuming that you’ve already got a S3 site up, check out the awesome documentation for this feature.
One gotcha that took me a while is that object-keys within S3 buckets do not begin with a
/, even though the request path traditionally begins with a
/. As such, do not include the preceding
/ within the
ReplaceKeyPrefixWith keys. Refer to
Example 1 within the docs for an illustration.