Can multiple domains be linked to individual directories within a single S3 bucket on Fastly?


I want to host many websites from inside individual directories of a single S3 bucket and have them linked to three different domains on Fastly like so:  =>  =>  =>
...  =>  some-bucket/site-n/index.html

I can do this using Cloudfront because its distributions support an additional path option which can route the request to the correct sub-directory inside the bucket. I don’t see a way to do this on Fastly and want to ask if anyone knows how this can be done?


@roman this is possible. For each URL path that you would want to rewrite, set up a new header rule like the following:

Then, with each new header rule, add a conditional like this:

What this does is do a swap of your bucket’s root directory to /path-you-define/ and then make sure that it only happens if the proper inbound host header is set.


@aspires can this be done through the APIs and therefore via the Fastly gem?


Yes. Everything in the Fastly app is build API-first, so you can use API calls to make these changes.


@aspires thanks I’ve been trying it but I’m having trouble setting the header regexp field. For some reason it is always ignored when I set it via the APIs:


condition = fastly_client.create_condition(
  :service_id =>,
  :version => latest_version_number,
  :name => 'host name condition',
  :priority => 10,
  :type => 'request',
  :statement => %Q(req.http.Host == "")


header = fastly_client.create_header(
  :service_id =>, 
  :version => latest_version.number, 
  :name => 'path-on-s3-bucket', 
  :ignore_if_set => false, 
  :type => 'request', 
  :dst => 'url',
  :src => 'req.url',
  :action => 'regex', 
  :regexp => '^/',
  :substitution => '/sites/path/version/',
  :request_condition =>

The above produces this result:

Sorry I can’t share photo links


@aspires never mind I figured out where things were going wrong:

The attribute name is not regexp it was regex. I was looking at lib/fastly/header.rb which confused the hell out of me.



I’m building a static site generator for a custom CMS.

We have potentially hundreds of clients/projects per client that need a custom domain name.

We intend to use a single s3 bucket to host all the sites using sub-directories since s3 has a hard limit on buckets.

I’ve been testing fastly vcl rules a way do setup this type of behaviour without much success (I get 404s when accessing)

But I have other question as well.
Does fastly provide a dedicated IP so that my clients can point their DNS CNAME’s to fastly

And then I would create a rule to redirect to the respective s3 bucket directory.

Is this scalable to hundreds of domains pointing to a single backend?



It may make sense to file a support ticket so we can take a deeper look at your VCL for this.

Yes, we do. But it’s a little more complex. If you mention it in that same email to discuss your VCL we can go over it.