Menu
Amazon CloudFront
Developer Guide (API Version 2016-08-01)

Configuring CloudFront to Cache Based on Query String Parameters

For web distributions, you can choose whether you want CloudFront to forward query string parameters to your origin. For RTMP distributions, you cannot configure CloudFront to forward query string parameters to your origin.

For both types of distributions, if you enable logging, CloudFront logs the full URL, including query string parameters. For web distributions, this is true regardless of whether you have configured CloudFront to forward query strings. For more information about CloudFront logging, see Access Logs.

For more information, see the applicable topic:

Query String Parameters and Web Distributions

For web distributions, you can specify whether you want CloudFront to include query strings when it forwards requests to your origin. For example, you can specify whether you want CloudFront to forward the ?parameter1=a part of the following URL:

http://d111111abcdef8.cloudfront.net/images/image.jpg?parameter1=a

If you configure CloudFront to forward query strings to your origin, CloudFront will include the query string portion of the URL when caching the object. For example, the following query strings cause CloudFront to cache three objects. This is true even if your origin always returns the same image.jpg regardless of the query string:

  • http://d111111abcdef8.cloudfront.net/images/image.jpg?parameter1=a

  • http://d111111abcdef8.cloudfront.net/images/image.jpg?parameter1=b

  • http://d111111abcdef8.cloudfront.net/images/image.jpg?parameter1=c

If your origin returns different versions of an object (for example, /images/image.jpg) based on the query string, select Yes for Forward Query Strings in the CloudFront console or specify true for the value of the QueryString element in the DistributionConfig complex type when you're using the CloudFront API.

If your origin returns the same version of an object regardless of the query string, select No or false. This increases the likelihood that CloudFront can serve a request from the cache, which improves performance and reduces the load on your origin.

The order of parameters matters in query strings. If you configure CloudFront to forward query strings to your origin, the following query strings cause CloudFront to cache two objects:

  • http://d111111abcdef8.cloudfront.net/images/image.jpg?parameter1=a&parameter2=b

  • http://d111111abcdef8.cloudfront.net/images/image.jpg?parameter2=b&parameter1=a

Case also matters in query strings. If you configure CloudFront to forward query strings to your origin, the following query strings cause CloudFront to cache two objects:

  • http://d111111abcdef8.cloudfront.net/images/image.jpg?parameter1=a

  • http://d111111abcdef8.cloudfront.net/images/image.jpg?parameter1=A

If you're using signed URLs to restrict access to your content (if you added trusted signers to your distribution), CloudFront removes the following query string parameters before forwarding the rest of the URL to your origin:

  • Expires

  • Key-Pair-Id

  • Policy

  • Signature

This means that if you're using signed URLs and you're configuring CloudFront to forward query string parameters to your origin, your own query string parameters cannot be named Expires, Key-Pair-Id, Policy, or Signature.

Query String Parameters and RTMP Distributions

For RTMP distributions, when CloudFront requests an object from the origin server, it removes any query string parameters. For example, if CloudFront receives the following request and media.flv is not already in the CloudFront cache:

http://d111111abcdef8.cloudfront.net/media/media.flv?parameter1=a

it sends the following URL to your origin server:

http://d111111abcdef8.cloudfront.net/media/media.flv