tomcat重写阀正在clientapp中创建一个循环

rta7y2nd  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(339)

我有一个vue spa,在tomcat中运行历史模式。为了解决404路由问题,我在tomcat中的~/conf/server.xml文件中添加了以下代码:

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

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

 ...
    </Host>
 ...

我已经在我的~/catalina/localhost/rewrite.config文件中添加了这段代码:(顺便说一句,我在不同的容器中有6个API,我认为它们可能是造成问题的原因?)

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

我重新启动了服务器,但仍然在数组中得到一个无限循环,该循环是从api填充的。如果删除rewrite.config,则不存在此问题。但是我又得到了404错误。。有什么想法吗?

ars1skjm

ars1skjm1#

通过在rewrite.config文件中更改此代码,解决了此问题。

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

相关问题