title: How can I exclude some routes from UseStatusCodePagesWithReExecute?
body: <p>I have a full-stack app in ASP.NET Core 5. The front-end is React and the back-end is OData.</p>
  <p>I need to use <code>app.UseStatusCodePagesWithReExecute(&quot;/&quot;);</code> in my <code>Configure()</code> method to redirect any unknown requests to <code>index.html</code>, as routing is handled by the client-side code.</p>
  <p>The problem is that in <code>OData</code> standard, when a key in a <code>GET</code> request is invalid, it returns a 404 error. This error will cause a redirect to <code>index.html</code> as well.</p>
  <p><strong>My Question: How can I exclude any request that starts with <code>/odata.svc</code> from <code>UseStatusCodePagesWithReExecute()</code>?</strong></p>
  <pre class="lang-cs prettyprint-override"><code>// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
      }            
  
      // generated swagger json and swagger ui middleware
      // You can access the swagger ui at /swagger/index.html 
      app.UseSwagger();
      app.UseSwaggerUI(x =&gt; x.SwaggerEndpoint(&quot;/swagger/v1/swagger.json&quot;, &quot;ASP.NET Core Sign-up and Verification API&quot;));
  
      //app.UseCors(&quot;CorsPolicy&quot;);
      // global cors policy
      app.UseCors(x =&gt; x
          .SetIsOriginAllowed(origin =&gt; true)
          .AllowAnyMethod()
          .AllowAnyHeader()
          .AllowCredentials());
  
      app.UseForwardedHeaders(new ForwardedHeadersOptions
      {
          ForwardedHeaders = ForwardedHeaders.All
      });
  
      app.UseRouting();
  
      // global error handler
      app.UseMiddleware&lt;ErrorHandlerMiddleware&gt;();
  
      // custom jwt auth middleware
      app.UseMiddleware&lt;JwtMiddleware&gt;();
  
      app.UseEndpoints(endpoints =&gt;
      {
          endpoints.Select().Expand().Filter().OrderBy().Count().MaxTop(30);
          // add an endpoint for an actual domain model
          // registered this endpoint with name odata (first parameter) 
          // and also with the same prefix (second parameter)
          // in this route, we are returning an EDM Data Model
          endpoints.MapODataRoute(&quot;odata.svc&quot;, &quot;odata.svc&quot;, GetEdmModel(app.ApplicationServices));
          endpoints.EnableDependencyInjection();
          endpoints.MapControllers();
          // enable serving static files
          endpoints.MapDefaultControllerRoute();
      });
  
      // Redirects any unknown requests to index.html
      app.UseStatusCodePagesWithReExecute(&quot;/&quot;);
  
      app.UseHttpsRedirection();
  
      // Serve default documents (i.e. index.html)
      app.UseDefaultFiles();
  
      //Set HTTP response headers
      const string cacheMaxAge = &quot;1&quot;;
      // Serve static files
      app.UseStaticFiles(new StaticFileOptions
      {
          OnPrepareResponse = ctx =&gt;
          {
              // using Microsoft.AspNetCore.Http;
              ctx.Context.Response.Headers.Append(
                      &quot;Cache-Control&quot;, $&quot;public, max-age={cacheMaxAge}&quot;);
          }
      });
  }
  </code></pre>