aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
456 stars 115 forks source link

Supports both Hugo URLs and SPA URLs #1077

Open xavierraffin opened 4 years ago

xavierraffin commented 4 years ago

Is your feature request related to a problem? Please describe.

I have an Amplify project that uses both Hugo and React as an SPA. Under /blog... the Hugo file are served and the rest is handled by the React SPA. Today the hosting is S3andCloudfront deployed by Amplify CLI and all URL works well (with trainling slahes too):

https://mydomain.com/blog ->  return the file /blog/index.html
https://mydomain.com/blog/ ->  return the file /blog/index.html
https://mydomain.com/blog/article1 ->  return the file /blog/article1/index.html
https://mydomain.com/blog/article1/ ->  return the file /blog/article1/index.html

https://mydomain.com -> return my SPA file /index.html
https://mydomain.com/other-spa-route -> return my SPA file /index.html  (and then React use the router to display the appropriate page)

Following the instruction from the doc, I try to do the same but fail.

The default behavior of Amplify Console hosting is perfect for the Hugo blog part (section Trailing slashes and Clean URLs) The section Redirects for Single Page Web Apps (SPA) is perfect for my React app.

But I can't have both!

If I set the SPA rule in place it catches all URLs for the blog and break the blog URLs (with trailing slashes). I am talking about this rule: </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>

Describe the solution you'd like

I like to have a SPA redirect rules that ignore a prefix. Like not catching urls under /blog... to let the default behavior applies.

Additional context

I tried playing with Regex but with no success. If Regex is possible please add that in the documentation.

kahdojay commented 4 years ago

Thanks for reporting @xavierraffin - I'll add this as a feature request and review with the team. You might be able to get this behavior by adding a "rewrite" for /blog/<> to /blog/<> as higher priority but would need to remove the 404 rewrite which wouldn't be ideal.

xavierraffin commented 4 years ago

Yes I confirm the rewrite rule works but lost 404.