title: Plotly/Dash web page not loading with IIS URL Rewrite
body: <p>I have a Plotly-Dash web application running as a service on a <code>Windows Server 2016</code> on port <code>50001</code>.</p>
  <p>I can directly access it via its port on a web browser. <a href="https://i.stack.imgur.com/0uwBw.png" rel="nofollow noreferrer">(working page via direct url)</a></p>
  <p>I configured the IIS server so that requests made to the route <code>/signatures</code> are rewritten to the service on <code>50001</code>. It seems to correctly request the page, but what I see is a page stuck on the loading screen. <a href="https://i.stack.imgur.com/To4xg.png" rel="nofollow noreferrer">(IIS URL not working)</a></p>
  <p>I feel like it is a problem between Dash and IIS but I'm not able to figure out why.</p>
  <p>My question is <strong>what should I do so that my web page is correctly displayed when I use IIS's URL Rewrite with Dash?</strong></p>
  <p>Here is my <code>web.config</code> file:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;configuration&gt;
      &lt;system.webServer&gt;
          &lt;rewrite&gt;
              &lt;rules&gt;
                  &lt;clear /&gt;
                  &lt;rule name=&quot;signatures&quot; stopProcessing=&quot;true&quot;&gt;
                      &lt;match url=&quot;^signatures/?(.*)&quot; /&gt;
                      &lt;conditions logicalGrouping=&quot;MatchAll&quot; trackAllCaptures=&quot;false&quot; /&gt;
                      &lt;action type=&quot;Rewrite&quot; url=&quot;http://localhost:50001/{R:1}&quot; /&gt;
                  &lt;/rule&gt;
                  &lt;!-- other rules --&gt;
              &lt;/rules&gt;
          &lt;/rewrite&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  <p>Thanks in advance.</p>
  <p><strong>Edit :</strong></p>
  <p>Here are the screenshots of the network tab for the two requests:</p>
  <ul>
  <li><a href="https://i.stack.imgur.com/8tuan.png" rel="nofollow noreferrer">network tab for direct URL</a></li>
  <li><a href="https://i.stack.imgur.com/CCUgA.png" rel="nofollow noreferrer">network tab for rewritten URL</a></li>
  </ul>
  <p>It seems like in the rewritten URL Dash requests all its resources from localhost and cannot get them.</p>
  <h1>Answer</h1>
  <p>Apparently I'm banned from answering questions (even my own !!), so I'm adding my answer as an edit.</p>
  <p>Based on @JennyDai 's suggestions I found that the client was not requesting the resources from the correct route.</p>
  <p>I found a workaround by editing the code to request local resources with the same prefix.</p>
  <p>In the creation of my Dash app, I set the parameter <code>requests_pathname_prefix</code> to have the same value as the prefix used in IIS.</p>
  <pre class="lang-py prettyprint-override"><code>app = dash.Dash(
      __name__,
      external_stylesheets=external_stylesheets,
      requests_pathname_prefix=f&quot;/dash/&quot;, # &lt;-- same as the prefix in IIS
  )
  </code></pre>
  <p><a href="https://dash.plotly.com/reference" rel="nofollow noreferrer">see dash.Dash in the API reference</a></p>
  <h2>Full example</h2>
  <p>Here is a full example for a test app running on port <code>50010</code> that should be accessible from <code>http://localhost/dash/</code></p>
  <h3>IIS config (<code>web.config</code>)</h3>
  <pre class="lang-xml prettyprint-override"><code>
  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;configuration&gt;
    &lt;system.webServer&gt;
      &lt;rewrite&gt;
        &lt;rules&gt;
          &lt;clear /&gt;
          &lt;!-- other rules --&gt;
          &lt;rule name=&quot;dash&quot; enabled=&quot;true&quot; stopProcessing=&quot;true&quot;&gt;
            &lt;match url=&quot;^dash/(.*)&quot; /&gt;
            &lt;conditions logicalGrouping=&quot;MatchAll&quot; trackAllCaptures=&quot;false&quot; /&gt;
            &lt;action type=&quot;Rewrite&quot; url=&quot;http://localhost:50010/{R:1}&quot; /&gt;
          &lt;/rule&gt;
          &lt;!-- other rules --&gt;
        &lt;/rules&gt;
      &lt;/rewrite&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  
  </code></pre>
  <h3>Python code</h3>
  <p>The code is based on <a href="https://dash.plotly.com/layout" rel="nofollow noreferrer">this tutorial</a> given by Plotly.</p>
  <pre class="lang-py prettyprint-override"><code>import dash
  import dash_core_components as dcc
  import dash_html_components as html
  import plotly.express as px
  import pandas as pd
  
  external_stylesheets = [&quot;https://codepen.io/chriddyp/pen/bWLwgP.css&quot;]
  
  PORT = 50010
  
  app = dash.Dash(
      __name__,
      external_stylesheets=external_stylesheets,
      requests_pathname_prefix=f&quot;/dash/&quot;, # &lt;-- same as the prefix in IIS
  )
  
  
  df = pd.DataFrame(
      {
          &quot;Fruit&quot;: [&quot;Apples&quot;, &quot;Oranges&quot;, &quot;Bananas&quot;, &quot;Apples&quot;, &quot;Oranges&quot;, &quot;Bananas&quot;],
          &quot;Amount&quot;: [4, 1, 2, 2, 4, 5],
          &quot;City&quot;: [&quot;SF&quot;, &quot;SF&quot;, &quot;SF&quot;, &quot;Montreal&quot;, &quot;Montreal&quot;, &quot;Montreal&quot;],
      }
  )
  
  fig = px.bar(df, x=&quot;Fruit&quot;, y=&quot;Amount&quot;, color=&quot;City&quot;, barmode=&quot;group&quot;)
  
  app.layout = html.Div(
      children=[
          html.H1(children=&quot;Hello Dash&quot;),
          html.Div(
              children=&quot;&quot;&quot;
      Dash: A web application framework for Python.
      &quot;&quot;&quot;
          ),
          dcc.Graph(id=&quot;example-graph&quot;, figure=fig),
      ]
  )
  
  
  if __name__ == &quot;__main__&quot;:
      app.run_server(debug=True, port=PORT)
  </code></pre>
  <p>After running the server here <a href="https://i.stack.imgur.com/EbAjp.png" rel="nofollow noreferrer">The page is displayed correctly with a rewritten URL</a>.</p>
  <h2>Problems with this workaround</h2>
  <p>Currently, the <a href="https://i.stack.imgur.com/mqmwx.png" rel="nofollow noreferrer">page does not display correctly when we try to connect directly to the port</a>. I'm fine with how it works for now.</p>
  <p>Another problem is that every time we want to change the URL in IIS we will need to redeploy the code with the same edit, but that's a minor problem currently.</p>
  <p>Thanks to @JennyDai for their help.</p>