title: Spring boot not forwarding url path to index.html React bundle
body: <p>I deployed a <strong>JAR</strong> for my REST API using <em>Spring boot</em>. The app also serves the <em>React web app bundle</em> through the <code>/static</code> directory.</p>
  
  <p>The problem is that when I try to enter this link:
  <a href="http://SERVER-IP/password/change/1d0afe95-a643-437e-8307-ed7688b6a756" rel="nofollow noreferrer">http://SERVER-IP/password/change/1d0afe95-a643-437e-8307-ed7688b6a756</a></p>
  
  <p>I see <code>Whitelabel Error Page 404</code> message mapped instead of the expected page.</p>
  
  <p>This issue isn't happening in my local environment, just in production (Ubuntu 16 vps).</p>
  
  <p>Here is the code of my <strong>WebMvcConfig</strong> class:</p>
  
  <pre><code>@Configuration
  public class WebMvcConfig implements WebMvcConfigurer {
  
      private final long MAX_AGE_SECS = 3600;
  
      @Override
      public void addCorsMappings(CorsRegistry registry) {
          registry.addMapping("/**")
                  .allowedOrigins("*")
                  .allowedMethods("HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE")
                  .maxAge(MAX_AGE_SECS);
      }
  
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
          registry.addViewController("/{spring:\\w+}")
                  .setViewName("forward:/");
          registry.addViewController("/**/{spring:\\w+}")
                  .setViewName("forward:/");
          registry.addViewController("/{spring:\\w+}/**{spring:?!(\\.js|\\.css)$}")
                  .setViewName("forward:/");
      }
  
  }
  </code></pre>
  
  <p><strong>POM.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.2.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;XXX&lt;/groupId&gt;
      &lt;artifactId&gt;XXX&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;XXX&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- For Working with Json Web Tokens (JWT) --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
              &lt;artifactId&gt;jjwt&lt;/artifactId&gt;
              &lt;version&gt;0.9.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- For Java 8 Date/Time Support --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.datatype&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-datatype-jsr310&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
              &lt;version&gt;2.0.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;executable&gt;true&lt;/executable&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>And here is the javascript code for the <strong>routes</strong>:</p>
  
  <pre><code>export const routes = (
    &lt;Switch&gt;
      &lt;PrivateRoute exact path="/" component={Routines} /&gt;
      &lt;PrivateRoute exact path="/home" component={Routines} /&gt;
      &lt;Route exact path="/login" component={Login} /&gt;
      &lt;Route exact path="/signup" component={Signup} /&gt;
      &lt;PrivateRoute exact path="/password/change" component={ChangePassword} /&gt;
      &lt;Route exact path="/password/change/:token" component={ChangePassword} /&gt;
      &lt;Route exact path="/password/reset" component={ResetPassword} /&gt;
      &lt;Route component={NotFoundPage} /&gt;
    &lt;/Switch&gt;
  );
  </code></pre>
  
  <p>All other routes are working fine either by React routing or by inserting the URL in the browser</p>
  
  <p>How can I do to forward all routes to index.html, even in production?</p>