title: URL rewrite is not working in version Apache Tomcat 9.0.30. Why?
body: <p>When I make <code>RewriteEngine</code> on in <code>rewrite.config</code>, tomcat is terminating automatically on startup.</p>
  
  <p>Why is it happening ?</p>
  
  <p>The <code>rewrite.config</code> is given below :</p>
  
  <pre><code>    RewriteEngine On  
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]  
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d  
      RewriteRule ^ - [L]
      RewriteRule ^ /index.html
  </code></pre>
  
  <p>I am configuring tomcat for url rewriting . I have added below statement in conf/context.xml</p>
  
  <pre><code>  &lt;Valve className="org.apache.catalina.valves.rewrite.RewriteValve" /&gt;
    &lt;JarScanner scanClassPath="false" /&gt;
  </code></pre>
  
  <p>and I have kept rewrite.config in apache-tomcat-9.0.30\webapps\ROOT\WEB-INF
  folder</p>
  
  <p>what else configuration need to be done.</p>
  
  <p>with above configuration i am getting below exception on  start up of tomcat </p>
  
  <pre><code>     java.lang.IllegalStateException: Error starting child
              at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720)
              at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
              at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
              at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1133)
              at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1867)
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
              at java.util.concurrent.FutureTask.run(FutureTask.java:266)
              at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
              at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
              at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1045)
              at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:429)
              at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576)
              at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
              at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
              at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
              at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
              at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
              at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
              at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
              at java.util.concurrent.FutureTask.run(FutureTask.java:266)
              at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
              at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
              at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
              at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:498)
              at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
              at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474)
      Caused by: org.apache.catalina.LifecycleException: Failed to start component [RewriteValve[StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]]
              at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
              at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:176)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5063)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
              ... 37 more
      Caused by: java.lang.IllegalArgumentException: rewriteValve.invalidLine
              at org.apache.catalina.valves.rewrite.RewriteValve.parse(RewriteValve.java:642)
              at org.apache.catalina.valves.rewrite.RewriteValve.parse(RewriteValve.java:221)
              at org.apache.catalina.valves.rewrite.RewriteValve.startInternal(RewriteValve.java:173)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              ... 42 more
  </code></pre>