Web Hosting Philippines, Offshore Programming, Offshore SEO Philippines, Cheap Webhosting Manila Philippines
Home -> Resources -> AWS -> AWS S3 - Aliasing a subdomain to a differently-named bucket

Pointing/Aliasing Multiple Subdomains to an S3 bucket

A typical use-case for Amazon S3 buckets is to have a domain or subdomain domain pointed to the contents of a bucket. For this to work, the domain or subdomain has to be the same as the name of the bucket being pointed to. e.g. a subdomain s3bucket.neotitans.com will (only) point to a bucket identically named as 's3bucket.neotitans.com'. [1]

If you need multiple or differently named subdomains pointing to the contents of a bucket, how do you go about this?

The most obvious way to change the subdomain pointing to a bucket is by renaming the bucket to have the same name as the new subdomain. Unfortunately, as of this writing, Amazon S3 buckets cannot be renamed. Thus, you have to create a new bucket with the new name that you want and copy the contents of the old bucket over. This is not a big problem if you don't have too many objects in the old bucket, but if you have a huge number of objects in an existing bucket, you might balk at having to do the copy.

In order to avoid creating a second bucket, you can maintain the existing subdomain pointed to the bucket and then alias/point additional subdomains to that one. The problem with this approach is that if you do this via a standard redirect from the new subdomain to the old one, the the URL in your browser will change as well. Ideally, you want the new subdomain to show the contents of the bucket as if it were directly pointed to it without the URL in the browser redirecting.

Below is the .htaccess code that shows how to make this happen. The key to making this work is the P option in the RewriteRule below. For this to work, you will need to make sure that mod_proxy is enabled in your Apache configuration:

RewriteEngine on

RewriteCond %{HTTP_HOST}   sub2.domain.com [NC] # the subdomain you want to alias to the old without redirecting
RewriteRule ^(.*)$         http://sub1.domain.com/$1 [L,P]  # pointing, via proxy, to the bucket called sub1.yourdomain.com
# Below is the standard way of redirecting that will cause the browser to update the URL
# RewriteRule ^(.*)$         http://sub1.domain.com/$1 [L,R=301]
          
 Want to tip via bitcoin?

(address string below for double checking)
 1KDgw4y5AUSUhmRVQSWiVS43YvrrxLmc8u
Back to Top

© 2017 by Andy Sy
last updated: 2012-Jun-3




Web Development / Rich Internet Applications (RIA) Development

Programming Languages

Platforms

Database Development

Web Hosting Philippines, Offshore SEO, Guaranteed SEO Philippines
   © 2003-2015 Neotitans Technologies Inc.