Understanding Cloudfronts Behavior Path pattern

Viewed 32

I'm currently using CloudFront to deliver a webpage that is hosted on an S3 Bucket. On a subpath /cms I want to route all traffic to a PHP-based content management system that is running on EC2 and Apache and also has an API that is serving the data for my frontend.

I have huge trouble getting the traffic properly routed to the CMS. I added the EC2 instance as an origin and added this behavior to it. enter image description here

This also reaches my Apache server. Problem is that all further paths lead to a 404 from Cloudfront. When I change the path pattern to /cms/* paths like /cms/api seem to work, but /cms alone will lead to a 404. What's the correct way to just have anything with the beginning with the path /cms being routed to by backend?

1 Answers

Because "/cms" does not match with "/cms/*"

and that is why CloudFront forward your traffic to S3 with show 404 not found error

If you want like that, set path pattern to "/cms/*" and make your your PHP application has all API with prefix /cms/

Related