简体   繁体   中英

How can I specify a path pattern of "/" in a CloudFront behavior?

I have a CloudFront distribution with an S3 origin. I want to create a behavior such that requests to the root path of the site will use a different origin (a webservice).

So ideally my behaviors would be:

  • "/" - webservice origin
  • Default (*) - S3 bucket

However, the above doesn't seem to work - the root request isn't caught by the first behavior.

Is there any way I can accomplish what I want using path patterns?

The answer is that a Cache Behavior with a Path Pattern of '/' does work to only match the root url. In this particular case, the user also had a default root object set which gets matched before the behavior patterns. Removing the default root object is necessary if you wish to define a cache behavior on the root url using the '/' pattern.

In addition to clearing my default root object like the other answer says, I had to set a different cache policy for my two behaviors. This was because CloudFront was using default cache key for the object.

I first added a custom header to my origin configurations 在此处输入图像描述

And then I made a new cache policy which referenced this custom header in the cache key.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM