0

I have single page react app on AWS (content being served from S3 origin through cloud front distribution via registered public domain name). We are wanting to add a context root to the url that is being used to get to the index.html (so the app). Current url - https://host.com/init Desired url - https://host.com/contextRoot/init

What are the ideas to achieve this type of url (with context root)? I believe the context root can not be added/mapped in cloud front or the public domain registry itself. If that is the case, what are the options ? Suggestions please.

The use case is that callers of the app come in with that context root in the url.

An And
  • 155
  • 1
  • 3
  • 14
  • 2
    I'm not clear do you want to redirect https://host.com to https://host.com/contextRoot? – MarcC Jul 27 '23 at 16:18
  • The callers of the app come in with that context root in the url. – An And Jul 27 '23 at 17:15
  • 1
    Add `/contextRoot/` to the prefix of all the objects in the S3 bucket. In other words: create that "folder" in S3 and move all your files into it. Otherwise, you'll have to place CloudFront in front off the S3 bucket, and use a custom origin path configuration, or maybe a CloudFront function or Lambda@Edge to rewrite the origin path. Changing the actual paths in S3 to match the requests coming in is by far the easiest fix. – Mark B Jul 27 '23 at 18:54

1 Answers1

0

The best as well as a multitude of other options are listed here :- S3 Static Website Hosting Route All Paths to Index.html. My own research says that domain host or the cloud front distribution can not be updated to have a custom context root defined. Instead the app needs to handle through one or more of functions (I call them tricks) listed in the above link to handle the request.

An And
  • 155
  • 1
  • 3
  • 14