Search code examples
vue.jstomcaturl-rewritingbrowser-historyserver-configuration

Tomcat Rewrite Valve is creating a loop in clientapp


I have a Vue SPA with History-mode running in tomcat. To solve a 404 routing issue i have added this code to my ~/conf/server.xml file in tomcat:

 ...
    <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

      <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />

 ...
    </Host>
 ... 

and i have added this code to my ~/Catalina/localhost/rewrite.config file: (btw i have 6 apis in different containers, i think they are the thing creating the issue maybe?)

 RewriteRule ^/api1/ - [L,NC]
 RewriteRule ^/api2/ - [L,NC]
 RewriteRule ^/api3/ - [L,NC]
 RewriteRule ^/api4/ - [L,NC]
 RewriteRule ^/api5/ - [L,NC]
 RewriteRule ^/api6/ - [L,NC]
 RewriteCond %{REQUEST_PATH} !-f
 RewriteRule ^/(.*) /index.html

I have restarted my server and still i am getting an infinite loop in my arrays that are being populated from my api's. The issue does not exist if i remove the rewrite.config. But then i get the 404 error again.. Any ideas?


Solution

  • This issue was solved by changing to this code in the rewrite.config file.

       RewriteRule ^/myapi1/.* - [L,NC]
       RewriteRule ^/myapi2/.* - [L,NC]
       RewriteRule ^/myapi3/.* - [L,NC]
       RewriteRule ^/myapi4/.* - [L,NC]
       RewriteRule ^/myapi5/.* - [L,NC]
       RewriteRule ^/host-manager/.* - [L,NC]
       RewriteRule ^/manager/.* - [L,NC]
       RewriteCond %{REQUEST_PATH} !-f
       RewriteRule ^/(.*) /index.html