【问题标题】:How to add multiple rewrite rules for multiple angular projects in the rewrite.config file in Tomcat 9如何在Tomcat 9的rewrite.config文件中为多个角度项目添加多个重写规则
【发布时间】:2021-01-06 04:34:30
【问题描述】:

以下是我面临的问题,需要一些帮助。

最初的问题:

我有一个 tomcat 服务器,我在其中部署了三个 angular 项目(在 web 应用程序文件夹内)。 当我启动 Tomcat 服务器时,会出现 Angular 应用程序。一旦我登录到应用程序并浏览页面,然后尝试刷新角度应用程序内的任何页面,它就会给我一个 404 错误。

初始问题的解决方案:

我得到了解决上述问题的解决方案,如下所示:

  1. 将以下参数添加到 Tomcat 配置文件夹内的“server.xml”文件中。 范围:-

  2. 我在 /config/Catalina/localhost/ 文件夹中创建了一个 rewrite.config 文件,并为所有 3 个 Angular 应用程序编写了重写规则。

新问题:

只有一个 Angular 应用程序正在启动,但所有其他应用程序的 index.html 页面都没有加载,并且在日志中我可以看到 304 错误。

问题:有人可以建议如何在同一个 tomcat rewrite.config 文件中为不同的 Angular 项目编写多个重写配置。

更多详细信息:Angular 应用程序位于以下位置:

Tomcat 路径/webapps/app1 Tomcat路径/webapps/app2 Tomcat路径/webapps/app3

rewrite.config 文件内容:

RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/app1/(.*) /app1/index.html

RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/app2/(.*) /app2/index.html

RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/app3/(.*) /app3/index.html

只有 app1 正在加载,但 app2 和 app3 index.html 页面未加载,并且 tomcat 日志中 app2 和 app3 的日志为 304。

请建议如何为多个角度应用程序编写重写规则。

【问题讨论】:

    标签: angularjs tomcat angular-ui-router tomcat8 tomcat9


    【解决方案1】:

    您确定只是第一个而不是只是第三个在您的情况下正确投放吗?因为我认为您缺少 RewriteRule 标志 [L] ...最后一条规则:

    RewriteCond %{REQUEST_PATH} !-f
    RewriteRule ^/app1/(.*) /app1/index.html [L]
    
    RewriteCond %{REQUEST_PATH} !-f
    RewriteRule ^/app2/(.*) /app2/index.html [L]
    
    RewriteCond %{REQUEST_PATH} !-f
    RewriteRule ^/app3/(.*) /app3/index.html [L]
    

    【讨论】:

      猜你喜欢
      • 2014-04-26
      • 1970-01-01
      • 2015-01-14
      • 2019-12-12
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多