title: Amazon S3 Redirect Rule - Preserve Query Params
body: <p>I noticed <a href="https://stackoverflow.com/questions/23993675/amazon-s3-redirect-rule-get-data-is-missing">Amazon S3 Redirect rule - GET data is missing</a> but after following the accepted answer my query params still are not being preserved.</p>
  
  <p>I have a site that uses React and React Router, meaning I have several URLs that load identical HTML and JS and then the JS figures out which part of the app to load based on the URL.</p>
  
  <p>For example:</p>
  
  <p>/foo, /bar, /baz all should load index.html, which loads bundle.js. Then bundle.js observes the URL and routes to some React component (also in bundle.js).</p>
  
  <p>However no foo, bar, or baz file exists in S3, only index.html. What I want to do is when I get a 404, redirect to /#!/{URL} (eg. /foo redirects to /#!/foo). This works fine with my redirect rule (below). However, I also want to bring query params with me (eg. /foo?ping=pong redirects to /#!/foo?ping=pong) but instead /foo?ping=pong just redirects to /#!/foo.</p>
  
  <p>Here are my redirect rules:</p>
  
  <pre><code>&lt;RoutingRules&gt;
      &lt;RoutingRule&gt;
          &lt;Condition&gt;
              &lt;HttpErrorCodeReturnedEquals&gt;404&lt;/HttpErrorCodeReturnedEquals&gt;
          &lt;/Condition&gt;
          &lt;Redirect&gt;
              &lt;Protocol&gt;http&lt;/Protocol&gt;
              &lt;HostName&gt;www.mydomain.com&lt;/HostName&gt;
              &lt;ReplaceKeyPrefixWith&gt;#!/&lt;/ReplaceKeyPrefixWith&gt;
          &lt;/Redirect&gt;
      &lt;/RoutingRule&gt;
  &lt;/RoutingRules&gt;
  </code></pre>
  
  <p>Any ideas on some way I can achieve this? Ideally without having to go change something in S3/CloudFront every time I add a new page?</p>