Does changing a URI in CloudFront Functions change the selected origin?

The Citead team, updated

In short. Changing request.uri changes the requested object while the selected cache behavior and origin remain unchanged.

Definition: No. In a CloudFront Functions request event, changing request.uri changes the object requested, while CloudFront keeps the request's selected cache behavior and the origin used for the origin request. The function edits the URI inside the request object returned to CloudFront.

Key facts

  • Amazon Web Services defines uri as the relative path of the requested object in the CloudFront Functions request object. The same event reference says the object is the actual request CloudFront received from the viewer.
  • A changed uri must begin with /, and changing it changes the object requested by the viewer. The event reference states that the change keeps both the cache behavior and the origin for the origin request unchanged.
  • A cache behavior applies to requests that match its path pattern. CloudFront compares the requested path with path patterns in their distribution order, and the first match selects the cache behavior, according to Cache behavior settings.
  • The default cache behavior is processed last when additional behaviors exist. It applies when the request does not match another path pattern.
  • CloudFront ignores query strings and cookies when evaluating a path pattern.

How does CloudFront select the cache behavior?

CloudFront evaluates the end-user request against the distribution's path patterns in their listed order. The first matching pattern determines the cache behavior. For example, a request matching both images/* and *.gif uses the behavior listed first in the distribution.

The default cache behavior is the fallback in this sequence. AWS documents its path pattern as * for a new distribution and says that it cannot be changed. Path patterns also exclude query strings and cookies from this evaluation, so those request parts do not select a different behavior.

CloudFront normalizes URI paths consistently with RFC 3986 before matching them to a cache behavior. After the match, it sends the raw URI path to the origin. This normalization is a separate matching rule from the later request.uri edit in a function.

What does a CloudFront Function URI rewrite change?

The event reference describes request.uri as the relative path of the requested object. A function can return a request object with a different value, provided the new value starts with a forward slash. A minimal request edit has this shape:

var request = event.request;
request.uri = "/media/index.mpd";
return request;

The changed value selects the object that the viewer requests. AWS explicitly documents that it does not change the cache behavior for the request or the origin to which an origin request is sent. The rewrite therefore stays within the behavior already selected for the incoming request.

How can you check a rewrite and its origin?

Start with the incoming path and compare it with the distribution's path patterns in order. Record the first matching behavior, including the default behavior when no other pattern matches. Then inspect the function's returned request.uri as the object path.

Finally, inspect the origin or origin group configured on that cache behavior. AWS describes this setting as identifying the origin to which CloudFront routes a request when the request matches the behavior's path pattern. A different object path can therefore be sent through the same selected behavior and origin after the function returns the request object.

FAQ

If /old becomes /new, does CloudFront select the behavior for /new?

No. The CloudFront Functions event reference says that changing uri changes the requested object while leaving the request's cache behavior and origin unchanged.

CloudFront's cache behavior documentation says that it does not consider query strings or cookies when evaluating a path pattern. The path pattern and its order determine the behavior.

Sources

  1. Amazon Web Services, "CloudFront Functions event structure", accessed 17 October 2026
  2. Amazon Web Services, "Cache behavior settings", accessed 17 October 2026

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark