Using Fastly to host a site in a subfolder?



  • Austin Spires

    This isn't possible with DNS, unfortunately. I did see this option on StackOverflow, but it assumes that is being served directly out of origin.

    The option you suggested -- working within your customer's Fastly account, is something that we've seen other organizations do before.

  • Sam Saffron

    By "working within fastly" I assume you just set up multiple backends and then use a rule to direct traffic to the correct origin. Is there an example config for this somewhere?

  • Austin Spires

    It's pretty easy, actually. You just add a second backend to the service, and set a conditional on the new backend like this:

    This will route all traffic matching the path /discourse to the Discourse backend.

  • emathy

    I have a use case pretty close to this, but I haven't quite figured out if or how it's possible.

    Site 1 is at one host, and needs to be served at Site 2 is at a second host, and needs to be served at (but has a subdomain of for DNS purposes).

    I have no access, alas, to the web server configurations. The usual methods via mod_rewrite aren't available. I've played a bit with Fastly, and it seems like on the surface I could set up two backends (main, blog) and a conditional that looks for any ^/blog requests, sending those to the blog backend. The thing is, though, that method seems to be more of a redirect, sending those requests to the Blog backend results in being served.

    Is there any way to do this with Fastly?


  • Rogier Mulhuijzen

    What's probably happening is that your blog origin doesn't like the Host: header, and serves the redirect.

    There's two things you can do:

    1. Add to the webserver configuration.
    2. Rewrite the Host header to a hostname it does like (i.e. in your Fastly config.

    Just add a Header object to set it, and put the same condition on it as you used for the origin selection.



  • Rogier Mulhuijzen

    Just to clarify, I changed from to, since that is what one is supposed to use in examples. :smile:

    Hope that didn't confuse anyone.

Please sign in to leave a comment.