Tomcat的8 URL重写 [英] Tomcat 8 URL Rewrite

查看:2106
本文介绍了Tomcat的8 URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AngularJS web应用和泽西后端。我需要设置URL重写,所以除了给定的异常都将被改写到角的index.html的。

I have an AngularJS webapp and Jersey backend. I need to setup URL rewriting, so everything except given exceptions will be rewritten to Angular's index.html.

例如:

http://my.domain.com/about will be rewritten
http://my.domain.com/photos/photo1.jpg will NOT be rewritten (file photo 1 exists)
http://my.domain.com/rest/myservice will be NOT be rewritten (it is a call to REST service)

我已经设置了Tomcat的8 URL重写阀门如下:

I have set up the Tomcat 8 URL Rewrite Valve as follows:

的conf / server.xml中

<Host name="my.domain.com" appBase="webapps/MyDomainServer" unpackWARs="true"
           autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">
  <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
  <!-- access logging, aliases,...-->
</Host>

的conf /卡塔利娜/ my.domain.com / rewrite.config

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} ^/rest.*
RewriteRule ^ - [L]

RewriteRule ^ index.html [L]

Tomcat的忽略我重写的设置,没有被改写,没有错误/例外是在日志中。我究竟做错了什么?先谢谢了。

Tomcat ignores my rewrite settings, nothing is rewritten, no error/exception is in the log. What am I doing wrong? Thanks in advance.

我曾试图移动RewriteValve在META-INF到config.xml和重写配置到WEB-INF,但它以同样的方式表现。

I have tried to move RewriteValve to config.xml in META-INF and rewrite config to WEB-INF, but it behaved in the same way.

推荐答案

我已经找到了解决办法,问题是在错误/故障rewrite.config文件。
正确的应该是:

I have found the solution, problem was in wrong/faulty rewrite.config file. Correct should be:

RewriteCond %{REQUEST_URI} ^/(css|img|js|partials|rest|favicon).*$
RewriteRule ^.*$ - [L]

RewriteRule ^.*$ /index.html [L,QSA]

在第一行列举不应该被重写的URI。其他将被重写的index.html。

On the first line are enumerated URIs which should not be rewritten. Everything else will be rewritten to index.html.

这篇关于Tomcat的8 URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆