LOG IN SIGN UP
Documentation

Routing assets to different origins

  Last updated May 23, 2017

Some customers have assets stored on multiple origin servers and want to route various requests to specific, different servers based on criteria they supply (e.g., asset type, file directory, host header). Fastly offers customers the ability to set conditions on their origins, which simply adds an if statement block to your VCL.

Basic setup: Create conditions for each origin

  1. Log in to the Fastly web interface and click the Configure link.
  2. From the service menu, select the appropriate service.
  3. Click the Configuration button and then select Clone active. The service version page appears.
  4. Click the Origins link. The Origins page appears.
  5. Click the Attach a condition link to the right of the name of an origin server. The Create a new request condition window appears.

    a new condition to redirect hosts

  6. Fill out the Create a new request condition fields as follows:
    • In the Name field, type a human-readable name for the condition.
    • In the Apply if field, type the conditions that you want to apply to your origin server. For example, for hosts, you could type req.http.host ~ "www.example.com". Or, for content-type / URL, you could type req.url ~ ".(jpg|png|gif)($|\?)".
  7. Click the Save and apply to button. The new condition appears on the Origins page.
  8. Click the Activate button to deploy your configuration changes.

Backup setup: Create a header

What if you have a condition already assigned to your origin? Although you can group request conditions on the origin with an 'and' or 'or' clause, there can only ever be one condition rule attached to that origin. If you want to separate your request conditions instead of grouping them, you can use header rules to route assets to different origins instead.

  1. Log in to the Fastly web interface and click the Configure link.
  2. From the service menu, select the appropriate service.
  3. Click the Configuration button and then select Clone active. The service version page appears.
  4. Click the Content link. The Content page appears.
  5. Click the Create header button. The Create a header page appears.

    the Create a header page

  6. Fill out the Create a header fields as follows:
    • In the Name field, type Image Backend (or any meaningful, preferred name).
    • From the Type menu, select Request, and from the Action menu, select Set.
    • In the Destination field, type backend.
    • In the Source field, type Image_Backend. (This should match the name of your global origin server. You can see the exact name if you look at your VCL. Click on the VCL button at the top of the page.)
    • From the Ignore if set menu, select No.
    • In the Priority field, type 10.
  7. Click the Create button. The new header appears on the Content page.
  8. On the Content page, click the Attach a condition link next to the header you just created. The Create a new request condition window appears.

    a new condition to redirect

  9. Fill out the Create a new request condition fields as follows:
    • In the Name field, type Redirect Images (or any meaningful, preferred name).
    • In the Apply if field, type req.url ~ "\.(jpg|png|gif)($|\?)".
  10. Click the Save and apply to button. The condition appears on the Content page.
  11. Click the Activate button to deploy your configuration changes.

Back to Top