title: IIS 8.5 rewrite rule subdirectory and ReactJs
body: <p>I have been struggling to understand the rewrite rules in IIS 8.5 and would like some help. Basically for React app I would need to rewrite all the urls to enter at index.html plus optional queryparams.</p>
  
  <p>the React app has to life in a sub director of the web server, as it is only an extension to the main-site</p>
  
  <p>so but for the assets (folder), static (folder) and manifest.json (file) I do not need it to rewrite the url. these would fall in </p>
  
  <ul>
  <li>www.some-site.com/catalog/door-selector/(folders or files and also the index.html)</li>
  </ul>
  
  <p>all routes would start here too, see 2 examples:</p>
  
  <ul>
  <li>www.some-site.com/catalog/door-selector/doors</li>
  <li>www.some-site.com/catalog/door-selector/doors/(name of the door)</li>
  </ul>
  
  <p>So I came up with the following: <em>(doesnt work)</em></p>
  
  <pre><code>&lt;rule name="Door Selector Door" patternSyntax="ExactMatch"&gt;
    &lt;match  url="^catalog/door-selector/.+" /&gt;
    &lt;conditions logicalGrouping="MatchAll"&gt;
      &lt;add input="{REQUEST_URI}" pattern="^~/static/~(.*)" negate="true" /&gt;
      &lt;add input="{REQUEST_URI}" pattern="^~/assets/~(.*)" negate="true" /&gt;
      &lt;add input="{REQUEST_URI}" pattern="^~/manifest.json" negate="true" /&gt; 
    &lt;/conditions&gt;
    &lt;action type="Rewrite" url="catalog/door-selector/index.html" appendQueryString="true"/&gt;
  &lt;/rule&gt;
  </code></pre>
  
  <p>With a simple rewrite and no conditions I get it to work but I would prefer to do it with only a couple of rules. </p>
  
  <p>note: I forgot that certain assets were coming from the production server. and that was rewriting parts of the url! </p>
  
  <p>final rule settled on:</p>
  
  <pre><code>&lt;rule name="Door Selector React" enabled="true"&gt;
    &lt;match  url="catalog/door-selector/(.*)" /&gt;
    &lt;conditions logicalGrouping="MatchAll"&gt;
      &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /&gt;
      &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt;
    &lt;/conditions&gt;
    &lt;action type="Rewrite" url="catalog/door-selector/index.html" appendQueryString="true"/&gt;
  &lt;/rule&gt;
  </code></pre>