Routing assets to different origins

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 power to set conditions on their origins, which simply adds an if statement block to your VCL.

Basic setup: Create conditions for each origin

To add a condition on your origin, navigate to Hosts → Backends within the Fastly application. Click the gear icon next to a specific origin, and select Conditions from the menu that appears to create the new condition you wish to apply to that origin. Here are some example criteria and the conditions that would be placed in the Apply If field of the New Condition you create:

Criteria Sample Conditions
hosts req.http.host ~ "www.example.com"
content-type / url req.url ~ ".(jpg|png|gif)($|\?)"

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.

Within the Fastly application, navigate to Content → Headers. Then select the New button to create the first header that will set the default origin.

ia new header

Set the first header's controls as follows:

Once you've set the controls, click Create to add the first new header.

Next click the gear icon to add a condition. Select New to add a new condition.

a new condition to redirect

Enter the condition settings as follows:

Once you have finished, click Create to assign the condition to your header. Then click the Activate button, near the top right corner of the window, to deploy the new version of the service you just edited.

Back to Top