I am hosting a website on aws amplify which was made with react.js. According to AWS I am suppose to add this rule </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>
in the rewrites/redirects in order for the routes in my app to show up. However I have also created a sitemap.xml
which works on localhost but not on the live site. I know it's because of the rule because when I remove the rule, the sitemap loads on the live site, but then my routes don't work.
Is there another rule I need to add for the sitemap.xml
to work or maybe edit the one above? This is the docs where I found the rule above AWS DOCS. Thanks in advance for the help! :)
The rule you have now is matching based on file extensions – css, gif, and so on. Without knowing more about the specific system you're working with, I can't say for certain this will fix your problem, but I think if you add xml
to the list of extensions, it'll solve this problem.
From the documentation to which you linked:
Using regular expressions, the following example sets up a 200 rewrite for all files to index.html except for the specific file extensions specified in the regular expression.
Right now, I'd guess the reason sitemap.xml isn't working is because that rule is sending all requests for sitemap.xml
to index.html
for your React app to serve. If you exclude URLs ending in xml
, it won't redirect it anymore.