I have two static web apps (create-react-apps) that are currently in two separate S3 buckets. Both buckets are configured for public read + static web hosting, and visiting their S3 hosted URLs correctly display the sites.
Bucket 1 - First App:
index.html
static/js/main.js
Bucket 2 - Second App:
/secondapp/
index.html
static/js/main.js
I have setup a single Cloudfront for this - The default cloudfront origin loads FirstApp
correctly, such that www.mywebsite.com loads the index.html by default.
For the SecondApp
, I have set up a Cache Behavior so that the path pattern secondapp/*
points to the SecondApp bucket URL.
In my browser, when I visit www.mywebsite.com/secondapp/
it correctly displays the second web app.
If I omit the trailing slash however, I instead see the First App, which is undesired.
If I visit www.mywebsite.com/secondapp/something
, I am also shown the First App, which is also undesired. (I want it to load the .html of secondapp
)
Both apps are configured to use html5 push state via react-router-dom.
My desired behavior is that visiting the following displays the correct site/bucket:
www.mywebsite.com
- Currently working
www.mywebsite.com/secondapp/
- Currently working
www.mywebsite.com/secondapp
- (Without trailing slash) Not working, shows First App
www.mywebsite.com/secondapp/something_else
- Not working, show First App
How can I achieved the desired behavior?
Thanks!
secondapp/*
Precedence 1 is the default/*
– Saltwater